Skip to content

Commit

Permalink
Add WIP PC-9801 version
Browse files Browse the repository at this point in the history
  • Loading branch information
gameblabla committed Apr 8, 2023
1 parent 85fe831 commit c8c7174
Show file tree
Hide file tree
Showing 45 changed files with 1,859 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PC9801/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
frames/
frames/*
old-src/
*.exe

Binary file added PC9801/BAKURA.BIN
Binary file not shown.
Binary file added PC9801/BPF.ZX0
Binary file not shown.
Binary file added PC9801/CWSDPMI.EXE
Binary file not shown.
Binary file added PC9801/FRAME1.BIN
Binary file not shown.
Binary file added PC9801/FRAME2.BIN
Binary file not shown.
Binary file added PC9801/FRAME3.BIN
Binary file not shown.
Binary file added PC9801/FRAME4.BIN
Binary file not shown.
20 changes: 20 additions & 0 deletions PC9801/FRAMEPAL.gpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GIMP Palette
Name: FRAMEPAL
Columns: 16
#
85 34 17 Untitled
119 68 34 Untitled
153 68 34 Untitled
153 102 51 Untitled
204 85 34 Untitled
187 102 68 Untitled
221 102 51 Untitled
204 136 85 Untitled
238 119 68 Untitled
255 136 85 Untitled
221 170 119 Untitled
255 170 119 Untitled
238 187 153 Untitled
255 204 153 Untitled
255 221 187 Untitled
255 238 221 Untitled
Binary file added PC9801/FRAMES_IMAGES.zip
Binary file not shown.
Binary file added PC9801/GAME.EXE
Binary file not shown.
Binary file added PC9801/IMG.BIN
Binary file not shown.
23 changes: 23 additions & 0 deletions PC9801/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CC = wcl
MODE = c

DEFINES = -0 -ox -bcl=dos -m$(MODE) -s -I. -DTARGET_MSDOS=16

CFLAGS += $(DEFINES)

OUTPUT = GAME.EXE

SOURCES = ./main.c gfx.c input.c

all: asm ${OUTPUT}

asm:
nasm -f obj decomp/zx0.asm -o zx0.o
nasm -f obj decomp/lzsa1.asm -o lzsa1.o

${OUTPUT}: ${SOURCES}
${CC} ${CFLAGS} -fe=${OUTPUT} ${SOURCES} zx0.o lzsa1.o
rm *.o *.err

clean:
rm *.o ${OUTPUT} *.err
12 changes: 12 additions & 0 deletions PC9801/NEW.gpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
GIMP Palette
Name: NEW
Columns: 16
#
0 0 0 Untitled
17 17 51 Untitled
51 34 17 Untitled
102 85 68 Untitled
187 153 119 Untitled
170 170 187 Untitled
221 187 102 Untitled
204 204 221 Untitled
20 changes: 20 additions & 0 deletions PC9801/PALETTE.gpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GIMP Palette
Name: PALETTE
Columns: 16
#
0 0 0 BLACK
27 28 53 DARK GRAY
50 42 30 BROWN
104 87 64 LIGHT BROWN
79 92 156 LIGHT BLUE
91 92 114
148 125 157
143 157 198
191 153 122
173 166 187
211 187 103
200 197 208
237 210 181
220 210 245
232 231 246
255 255 255
Binary file added PC9801/TITLE.ZX0
Binary file not shown.
Binary file added PC9801/bakura.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PC9801/bakuraPC98-old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PC9801/bakuraPC98.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions PC9801/bios.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define INTERRUPT_VGA 0x18
#define VGA_SHOW_TEXT 0xC
#define VGA_HIDE_TEXT 0xD
#define VGA_START 0x40
#define VGA_STOP 0x41
#define VGA_MODE 0x42
15 changes: 15 additions & 0 deletions PC9801/convert_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
python convert_to_pc98.py "$1" TEMP.BIN
./crop.sh TEMP.BIN
lzsa -r -f1 TEMP.BIN_part1 T1.LZ
lzsa -r -f1 TEMP.BIN_part2 T2.LZ
lzsa -r -f1 TEMP.BIN_part3 T3.LZ
lzsa -r -f1 TEMP.BIN_part4 T4.LZ

echo "The size of T1 $(stat -c%s "T1.LZ") bytes"
echo "The size of T2 $(stat -c%s "T2.LZ") bytes"
echo "The size of T3 $(stat -c%s "T3.LZ") bytes"
echo "The size of T4 $(stat -c%s "T4.LZ") bytes"

cat T1.LZ T2.LZ T3.LZ T4.LZ > "$2".BIN
rm T1.LZ T2.LZ T3.LZ T4.LZ TEMP.BIN TEMP.BIN_part4 TEMP.BIN_part3 TEMP.BIN_part2 TEMP.BIN_part1
15 changes: 15 additions & 0 deletions PC9801/convert_image_zx0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
python convert_to_pc98.py "$1" TEMP.BIN
./crop.sh TEMP.BIN
zx0 TEMP.BIN_part1 T1.ZX0
zx0 TEMP.BIN_part2 T2.ZX0
zx0 TEMP.BIN_part3 T3.ZX0
zx0 TEMP.BIN_part4 T4.ZX0

echo "The size of T1 $(stat -c%s "T1.ZX0") bytes"
echo "The size of T2 $(stat -c%s "T2.ZX0") bytes"
echo "The size of T3 $(stat -c%s "T3.ZX0") bytes"
echo "The size of T4 $(stat -c%s "T4.ZX0") bytes"

cat T1.ZX0 T2.ZX0 T3.ZX0 T4.ZX0 > "$2".ZX0
rm T1.ZX0 T2.ZX0 T3.ZX0 T4.ZX0 TEMP.BIN TEMP.BIN_part4 TEMP.BIN_part3 TEMP.BIN_part2 TEMP.BIN_part1
47 changes: 47 additions & 0 deletions PC9801/convert_to_pc98.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
import numpy as np
from PIL import Image

def to_planar(image_data, width, height):
planes = [np.zeros((height, width // 8), dtype=np.uint8) for _ in range(4)]

for y in range(height):
for x in range(width):
color = image_data[y, x]
pos = x // 8
bit_mask = 1 << (7 - (x % 8))

for plane_index in range(4):
if color & (1 << plane_index):
planes[plane_index][y, pos] |= bit_mask
else:
planes[plane_index][y, pos] &= ~bit_mask

return np.concatenate(planes)

if len(sys.argv) != 3:
print("Usage: python PNGtoPC98.py input.png output.bin")
sys.exit(1)

input_file_path = sys.argv[1]
output_file_path = sys.argv[2]

# Load the PNG image
image = Image.open(input_file_path)

# Ensure image has 16 colors
if image.mode != 'P' or len(image.getpalette()) != 16 * 3:
print("Error: Image must be a 16-color indexed PNG.")
sys.exit(1)

width, height = image.size

# Convert image to planar format
image_data = np.array(image, dtype=np.uint8)
planar_data = to_planar(image_data, width, height)

# Write planar data to output file
with open(output_file_path, 'wb') as output_file:
output_file.write(planar_data.tobytes())

print(f"Converted '{input_file_path}' to planar format and saved as '{output_file_path}'")
23 changes: 23 additions & 0 deletions PC9801/crop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 inputfile"
exit 1
fi

inputfile="$1"

if [ ! -e "$inputfile" ]; then
echo "Error: File not found: $inputfile"
exit 1
fi

filesize=$(stat -c%s "$inputfile")
partsize=$((filesize / 4))

for i in {0..3}; do
skip=$((i * partsize))
outputfile="${inputfile}_part$(($i + 1))"
dd if="$inputfile" of="$outputfile" bs="$partsize" count=1 skip="$i" 2>/dev/null
echo "Created $outputfile"
done
126 changes: 126 additions & 0 deletions PC9801/decomp/lzsa1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
; decompress_small.S - space-efficient decompressor implementation for 8088
;
; Copyright (C) 2019 Emmanuel Marty
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.

segment .text
bits 16

; ---------------------------------------------------------------------------
; Decompress raw LZSA1 block
; inputs:
; * ds:si: raw LZSA1 block
; * es:di: output buffer
; output:
; * ax: decompressed size
; ---------------------------------------------------------------------------

GLOBAL lzsa1_decompress
GLOBAL lzsa1_decompress_
GLOBAL _lzsa1_decompress

lzsa1_decompress_:
_lzsa1_decompress:
lzsa1_decompress:
push di ; remember decompression offset
cld ; make string operations (lods, movs, stos..) move forward

xor cx,cx

.decode_token:
mov ax,cx ; clear ah - cx is zero from above or from after rep movsb in .copy_match
lodsb ; read token byte: O|LLL|MMMM
mov dx,ax ; keep token in dl
and al,070H ; isolate literals length in token (LLL)
mov cl,4
shr al,cl ; shift literals length into place

cmp al,07H ; LITERALS_RUN_LEN?
jne .got_literals ; no, we have the full literals count from the token, go copy

lodsb ; grab extra length byte
add al,07H ; add LITERALS_RUN_LEN
jnc .got_literals ; if no overflow, we have the full literals count, go copy
jne .mid_literals

lodsw ; grab 16-bit extra length
db 81H ; mask inc ah/lodsb
; (*like jmp short .got_literals but faster)

.mid_literals:
inc ah ; add 256
lodsb ; grab single extra length byte

.got_literals:
xchg cx,ax
rep movsb ; copy cx literals from ds:si to es:di

test dl,dl ; check match offset size in token (O bit)
js .get_long_offset

dec cx
xchg cx,ax ; ah to 0xff - cx was zero from the rep movsb above
lodsb
db 3CH ; mask lodsw
; (*like jmp short .get_match_length but faster)

.get_long_offset:
lodsw ; Get 2-byte match offset

.get_match_length:
xchg dx,ax ; dx: match offset ax: original token
and al,0FH ; isolate match length in token (MMMM)
add al,3 ; add MIN_MATCH_SIZE

cmp al,012H ; MATCH_RUN_LEN?
jne .got_matchlen ; no, we have the full match length from the token, go copy

lodsb ; grab extra length byte
add al,012H ; add MIN_MATCH_SIZE + MATCH_RUN_LEN
jnc .got_matchlen ; if no overflow, we have the entire length
jne .mid_matchlen

lodsw ; grab 16-bit length
test ax,ax ; bail if we hit EOD
je short .done_decompressing

db 81H ; mask inc ah/lodsb
; (*like jmp short .got_literals but faster)
.mid_matchlen:
inc ah ; add 256
lodsb ; grab single extra length byte

.got_matchlen:
xchg cx,ax ; copy match length into cx
push ds ; save ds:si (current pointer to compressed data)
xchg si,ax
push es
pop ds
mov si,di ; ds:si now points at back reference in output data
add si,dx
rep movsb ; copy match
xchg si,ax ; restore ds:si
pop ds
jmp short .decode_token ; go decode another token

.done_decompressing:
pop ax ; retrieve the original decompression offset
xchg ax,di ; compute decompressed size
sub ax,di
ret ; done
Loading

0 comments on commit c8c7174

Please sign in to comment.