Memory layout
@@ -52,19 +77,23 @@ Special locations:
@@ -171,7 +200,8 @@ following functions (and a few others):
Other hints
-- a good emulator to use for PC-Engine is "mednafen" ()
+
- is a good
+emulator to use for the PC-Engine.
some useful resources on PCE coding:
@@ -210,6 +240,3 @@ freely, subject to the following restrictions:
-
-
-
diff --git a/libsrc/geos-cbm/disk/dio_cts.s b/libsrc/geos-cbm/disk/dio_cts.s
index 8be343641..043e1f8d8 100644
--- a/libsrc/geos-cbm/disk/dio_cts.s
+++ b/libsrc/geos-cbm/disk/dio_cts.s
@@ -1,6 +1,6 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
-; 2.7.2001
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-26, Greg King
;
;
; unsigned char __fastcall__ dio_phys_to_log (dhandle_t handle,
@@ -59,7 +59,7 @@ _dio_phys_to_log:
lda (ptr3),y
tay
lda driveType,y
- and #%00000011 ; this is for RamDrive compatibility
+ and #%00001111 ; remove ramDisk flags
cmp #DRV_1541
beq dio_cts1541
cmp #DRV_1571
@@ -67,7 +67,7 @@ _dio_phys_to_log:
cmp #DRV_1581
beq dio_cts1581
- lda #DEV_NOT_FOUND ; unknown device
+ lda #INCOMPATIBLE ; unsupported device
ldx #0
beq ret
@@ -91,7 +91,7 @@ _inv_data:
lda #INV_TRACK
.byte $2c
_inv_hand:
- lda #INCOMPATIBLE
+ lda #DEV_NOT_FOUND
ldx #0
beq ret
diff --git a/libsrc/geos-cbm/disk/dio_openclose.s b/libsrc/geos-cbm/disk/dio_openclose.s
index ec5aa8795..72e3e32e9 100644
--- a/libsrc/geos-cbm/disk/dio_openclose.s
+++ b/libsrc/geos-cbm/disk/dio_openclose.s
@@ -1,8 +1,8 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-24, Greg King
;
; based on Atari version by Christian Groessler
-; 2.7.2001
;
; dhandle_t __fastcall__ dio_open (unsigned char device);
; unsigned char __fastcall__ dio_close (dhandle_t handle);
@@ -27,11 +27,13 @@ sectsizetab:
.code
_dio_open:
- pha
+ cmp #4
+ bcs _inv_drive
tax
lda driveType,x ; check if there's a device
beq _inv_drive
txa
+ pha
clc
adc #8 ; normalize devnum
sta curDevice
diff --git a/libsrc/geos-cbm/disk/dio_read.s b/libsrc/geos-cbm/disk/dio_read.s
index db46c9b69..ac19f9afa 100644
--- a/libsrc/geos-cbm/disk/dio_read.s
+++ b/libsrc/geos-cbm/disk/dio_read.s
@@ -1,6 +1,6 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
-; 2.7.2001
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-27, Greg King
;
; this file provides the _dio_read function
;
@@ -15,7 +15,9 @@
_dio_read:
jsr dio_params
+ tay
+ bne err
jsr ReadBlock
stx __oserror
txa
- rts
+err: rts
diff --git a/libsrc/geos-cbm/disk/dio_stc.s b/libsrc/geos-cbm/disk/dio_stc.s
index 586e3f3db..7398edb63 100644
--- a/libsrc/geos-cbm/disk/dio_stc.s
+++ b/libsrc/geos-cbm/disk/dio_stc.s
@@ -1,6 +1,6 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
-; 2.7.2001
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-27, Greg King
;
; unsigned char __fastcall__ dio_log_to_phys (dhandle_t handle,
; unsigned *sectnum, /* input */
@@ -55,7 +55,7 @@ _dio_log_to_phys:
lda (ptr3),y
tay
lda driveType,y
- and #%00000011 ; this is for RamDrive compatibility
+ and #%00001111 ; remove ramDisk flags
cmp #DRV_1541
beq dio_stc1541
cmp #DRV_1571
@@ -63,7 +63,7 @@ _dio_log_to_phys:
cmp #DRV_1581
beq dio_stc1581
- lda #DEV_NOT_FOUND ; unknown device
+ lda #INCOMPATIBLE ; unsupported device
ldx #0
beq _ret
@@ -86,7 +86,7 @@ _inv_data:
lda #INV_TRACK
.byte $2c
_inv_hand:
- lda #INCOMPATIBLE
+ lda #DEV_NOT_FOUND
ldx #0
beq _ret
@@ -102,8 +102,8 @@ _loop41:
bne _nxt
lda tmp1
cmp sectab_1541_l+1,x
- bcc _found
-_nxt: inx
+_nxt: bcc _found
+ inx
cpx #35
bne _loop41
beq _inv_data
@@ -124,12 +124,11 @@ dio_stc1571:
; - fall down to 1541
lda tmp2
cmp #>683
- bne _cnt71
+ bne _if71
lda tmp1
cmp #<683
- bcc dio_stc1541
+_if71: bcc dio_stc1541
-_cnt71:
lda tmp1
sec
sbc #<683
@@ -138,6 +137,8 @@ _cnt71:
sbc #>683
sta tmp2
jsr dio_stc1541 ; will fall through here
+ tay
+ bne _ret ; result beyond track 70
ldy #diopp_track
lda (ptr1),y
@@ -166,7 +167,7 @@ _sub81: lda tmp1
sbc #0
sta tmp2
inx
- cpx #81
+ cpx #80
bne _loop81
beq _inv_data
diff --git a/libsrc/geos-cbm/disk/dio_write.s b/libsrc/geos-cbm/disk/dio_write.s
index 14267803a..a5f747519 100644
--- a/libsrc/geos-cbm/disk/dio_write.s
+++ b/libsrc/geos-cbm/disk/dio_write.s
@@ -1,6 +1,6 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
-; 2.7.2001
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-27, Greg King
;
; this file provides the _dio_write function
;
@@ -15,5 +15,9 @@
_dio_write:
jsr dio_params
+ tay
+ bne err
jsr WriteBlock
jmp setoserror
+
+err: rts
diff --git a/libsrc/geos-cbm/disk/dio_writev.s b/libsrc/geos-cbm/disk/dio_writev.s
index 7cb9b029f..9b36ed096 100644
--- a/libsrc/geos-cbm/disk/dio_writev.s
+++ b/libsrc/geos-cbm/disk/dio_writev.s
@@ -1,6 +1,6 @@
;
-; Maciej 'YTM/Elysium' Witkowiak
-; 2.7.2001
+; 2001-07-02, Maciej 'YTM/Elysium' Witkowiak
+; 2015-08-27, Greg King
;
; this file provides the _dio_write function
;
@@ -15,7 +15,9 @@
_dio_write_verify:
jsr dio_params
+ tay
+ bne err
jsr VerWriteBlock
stx __oserror
txa
- rts
+err: rts
diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s
index 80b32c089..75ffb7f05 100644
--- a/libsrc/pce/crt0.s
+++ b/libsrc/pce/crt0.s
@@ -4,33 +4,26 @@
; by Groepaz/Hitmen
; based on code by Ullrich von Bassewitz
;
-; This must be the *first* file on the linker command line
+; 2018-02-11, Greg King
;
.export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import initlib, donelib
- .import push0, _main, zerobss
- .import initheap
+ .import push0, _main
.import IRQStub
- ; Linker generated
- .import __RAM_START__, __RAM_SIZE__
- .import __ROM0_START__, __ROM0_SIZE__
- .import __ROM_START__, __ROM_SIZE__
- .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
- .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
- .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
- .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__
- .import __BSS_SIZE__
+ ; Linker-generated
+ .import __CARTSIZE__
+ .import __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
+ .import __BSS_RUN__, __BSS_SIZE__
+ .import __MAIN_START__, __MAIN_SIZE__, __STACKSIZE__
.include "pce.inc"
.include "extzp.inc"
.importzp sp
- .importzp ptr1,ptr2
- .importzp tmp1,tmp2,tmp3
; ------------------------------------------------------------------------
; Place the startup code in a special segment.
@@ -53,29 +46,27 @@ start:
ldx #$FF ; Stack top ($21FF)
txs
- ; At startup all MPRs are set to 0, so init them
- lda #$ff
- tam #%00000001 ; 0000-1FFF = Hardware page
+ ; At power-on, most MPRs have random values; so, initiate them.
+ lda #$FF
+ tam #%00000001 ; $0000-$1FFF = Hardware bank
lda #$F8
- tam #%00000010 ; 2000-3FFF = Work RAM
-
- ; FIXME: setup a larger block of memory to use with C-code
+ tam #%00000010 ; $2000-$3FFF = Work RAM
;lda #$F7
- ;tam #%00000100 ; 4000-5FFF = Save RAM
- ;lda #1
- ;tam #%00001000 ; 6000-7FFF Page 2
- ;lda #2
- ;tam #%00010000 ; 8000-9FFF Page 3
- ;lda #3
- ;tam #%00100000 ; A000-BFFF Page 4
+ ;tam #%00000100 ; $4000-$47FF = 2K Battery-backed RAM
;lda #4
- ;tam #%01000000 ; C000-DFFF Page 5
- ;lda #0
- ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0
+ ;tam #%00001000 ; $6000-$7FFF
- ; Clear work RAM (2000-3FFF)
- stz <$00
- tii $2000, $2001, $1FFF
+ lda #$01
+ ldx #>$8000
+ cpx #>__CARTSIZE__
+ bcc @L1 ;(blt)
+ tam #%00010000 ; $8000-$9FFF = ROM bank 1 (32K block of ROM)
+ inc a
+ tam #%00100000 ; $A000-$BFFF = ROM bank 2
+ inc a
+@L1: tam #%01000000 ; $C000-$DFFF = ROM bank 3 (32K) or 1 (16K)
+ ;lda #$00 ; (The reset default)
+ ;tam #%10000000 ; $E000-$FFFF hucard/syscard bank 0
; Initialize hardware
stz TIMER_CTRL ; Timer off
@@ -91,15 +82,16 @@ start:
lda #$05
sta IRQ_MASK ; IRQ1=on
- ; Clear the BSS data
- jsr zerobss
-
; Copy the .data segment to RAM
tii __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
+ ; Clear the .bss segment
+ stz __BSS_RUN__
+ tii __BSS_RUN__, __BSS_RUN__ + 1, __BSS_SIZE__ - 1
+
; Set up the stack
- lda #<(__RAM_START__+__RAM_SIZE__)
- ldx #>(__RAM_START__+__RAM_SIZE__)
+ lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
+ ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
sta sp
stx sp + 1
diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile
index 9a4dd7506..a4a495c9a 100644
--- a/testcode/lib/pce/Makefile
+++ b/testcode/lib/pce/Makefile
@@ -1,12 +1,29 @@
.PHONY: all clean test
+# Size of cartridge to generate.
+# Possible values:
+# 8K = 0x2000
+# 16K = 0x4000
+# 32K = 0x8000
+CARTSIZE := 0x2000
+
+ifeq (${CARTSIZE},0x8000)
+COUNT := 3
+else
+COUNT := 1
+endif
+
all: conio.pce
-conio.pce: conio.c
- ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce
+%.pce: %.bin
+ dd if=$< bs=8K skip=${COUNT} > $@
+ dd if=$< bs=8K count=${COUNT} >> $@
+
+%.bin: %.c ../../../lib/pce.lib
+ ../../../bin/cl65 -t pce $< -Wl -D__CARTSIZE__=${CARTSIZE} -m $*.map -o $@
clean:
- $(RM) conio.o conio.pce conio.map
+ $(RM) conio.o conio.???
test: conio.pce
- mednafen -force_module pce conio.pce
+ mednafen -force_module pce $<
diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c
index ed3f86240..858f01918 100644
--- a/testcode/lib/pce/conio.c
+++ b/testcode/lib/pce/conio.c
@@ -45,7 +45,7 @@ void main(void)
p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]
);
}
- memcpy(p, main, 0); /* test that a zero length doesn't copy 64K */
+ memcpy(p, main, i = 0); /* test that a zero length doesn't copy 64K */
gotoxy(0,ysize - 1);
for (i = 0; i < xsize; ++i) {