From faccc5a3d640a111ac5b2e8a8f25debd77cc91b7 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sat, 29 Nov 2014 14:18:48 +0100 Subject: [PATCH 01/28] initial import, completely untested, does not compile yet --- libsrc/Makefile | 1 + libsrc/pcengine/_heap.s | 67 +++++++++ libsrc/pcengine/_scrsize.s | 17 +++ libsrc/pcengine/call.s | 19 +++ libsrc/pcengine/clock.s | 23 +++ libsrc/pcengine/clrscr.s | 27 ++++ libsrc/pcengine/color.s | 59 ++++++++ libsrc/pcengine/condes.s | 102 +++++++++++++ libsrc/pcengine/conio.s | 122 ++++++++++++++++ libsrc/pcengine/cputc.s | 117 +++++++++++++++ libsrc/pcengine/crt0.s | 233 +++++++++++++++++++++++++++++ libsrc/pcengine/huc6280.inc | 238 ++++++++++++++++++++++++++++++ libsrc/pcengine/joytokbd.s | 275 +++++++++++++++++++++++++++++++++++ libsrc/pcengine/kplot.s | 41 ++++++ libsrc/pcengine/pce-stdjoy.s | 191 ++++++++++++++++++++++++ libsrc/pcengine/pcengine.h | 74 ++++++++++ libsrc/pcengine/pcengine.inc | 75 ++++++++++ libsrc/pcengine/pcengine.x | 68 +++++++++ libsrc/pcengine/psg.s | 29 ++++ libsrc/pcengine/revers.s | 5 + libsrc/pcengine/vce.s | 16 ++ libsrc/pcengine/vdc.s | 46 ++++++ libsrc/pcengine/vga.inc | 129 ++++++++++++++++ 23 files changed, 1974 insertions(+) create mode 100644 libsrc/pcengine/_heap.s create mode 100644 libsrc/pcengine/_scrsize.s create mode 100644 libsrc/pcengine/call.s create mode 100644 libsrc/pcengine/clock.s create mode 100644 libsrc/pcengine/clrscr.s create mode 100644 libsrc/pcengine/color.s create mode 100644 libsrc/pcengine/condes.s create mode 100644 libsrc/pcengine/conio.s create mode 100644 libsrc/pcengine/cputc.s create mode 100644 libsrc/pcengine/crt0.s create mode 100644 libsrc/pcengine/huc6280.inc create mode 100644 libsrc/pcengine/joytokbd.s create mode 100644 libsrc/pcengine/kplot.s create mode 100644 libsrc/pcengine/pce-stdjoy.s create mode 100644 libsrc/pcengine/pcengine.h create mode 100644 libsrc/pcengine/pcengine.inc create mode 100644 libsrc/pcengine/pcengine.x create mode 100644 libsrc/pcengine/psg.s create mode 100644 libsrc/pcengine/revers.s create mode 100644 libsrc/pcengine/vce.s create mode 100644 libsrc/pcengine/vdc.s create mode 100644 libsrc/pcengine/vga.inc diff --git a/libsrc/Makefile b/libsrc/Makefile index 6a801695a..051e5cf3a 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -24,6 +24,7 @@ TARGETS = apple2 \ $(GEOS) \ lynx \ nes \ + pcengine \ sim6502 \ sim65c02 \ supervision diff --git a/libsrc/pcengine/_heap.s b/libsrc/pcengine/_heap.s new file mode 100644 index 000000000..71fa13e78 --- /dev/null +++ b/libsrc/pcengine/_heap.s @@ -0,0 +1,67 @@ +; +; Ullrich von Bassewitz, 03.06.1998 +; +; Heap variables and initialization. +; + +; FIXME: there should be a way to configure heap from linkerscript! + + .constructor initheap, 24 + + .import __RAM_START__, __RAM_SIZE__, __STACKSIZE__ ; Linker generated + .import __BSS_SIZE__ + .importzp sp + +.data + +;; old - remove + .export __horg, __hptr, __hend, __hfirst, __hlast +__horg: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__hptr: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Dito +__hend: + .word __RAM_START__+__RAM_SIZE__ +__hfirst: + .word 0 +__hlast: + .word 0 + + .export __heaporg + .export __heapptr + .export __heapend + .export __heapfirst + .export __heaplast + +__heaporg: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__heapptr: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__heapend: + .word __RAM_START__+__RAM_SIZE__ +__heapfirst: + .word 0 +__heaplast: + .word 0 + + +; Initialization. Will be called from startup! + +.code + +initheap: + ;sec + ;lda sp +; lda #<(__STACKSIZE__) +; lda #<(__RAM_START__+__RAM_SIZE__) + lda #<(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) + sta __heapend + sta __hend ; old +; lda sp+1 +; lda #>(__STACKSIZE__) +; lda #>(__RAM_START__+__RAM_SIZE__) + lda #>(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) + sta __heapend+1 + sta __hend+1 ; old + rts + diff --git a/libsrc/pcengine/_scrsize.s b/libsrc/pcengine/_scrsize.s new file mode 100644 index 000000000..17b23b709 --- /dev/null +++ b/libsrc/pcengine/_scrsize.s @@ -0,0 +1,17 @@ +; +; Screen size variables +; + + + +.export _screensize +_screensize: + ldx xsize + ldy ysize + rts + +.rodata + .export xsize, ysize + +xsize: .byte 64 +ysize: .byte 28 diff --git a/libsrc/pcengine/call.s b/libsrc/pcengine/call.s new file mode 100644 index 000000000..34fbac08b --- /dev/null +++ b/libsrc/pcengine/call.s @@ -0,0 +1,19 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; CC65 runtime: call function via pointer in ax +; + + .export callax + +.code + +callax: + sta vec + stx vec+1 + jmp (vec) ; jump there + +.bss + +vec: + .res 2 \ No newline at end of file diff --git a/libsrc/pcengine/clock.s b/libsrc/pcengine/clock.s new file mode 100644 index 000000000..d344814ad --- /dev/null +++ b/libsrc/pcengine/clock.s @@ -0,0 +1,23 @@ +; +; Ullrich von Bassewitz, 21.09.1998 +; +; clock_t clock (void); +; + + .include "pcengine.inc" + + .export _clock + .importzp sreg + +.proc _clock + + ldy #0 ; Byte 3 is always zero + sty sreg+1 + sty sreg + + ldx _tickcount+1 + lda _tickcount + rts + +.endproc + diff --git a/libsrc/pcengine/clrscr.s b/libsrc/pcengine/clrscr.s new file mode 100644 index 000000000..c2c5dcbcb --- /dev/null +++ b/libsrc/pcengine/clrscr.s @@ -0,0 +1,27 @@ + + .include "pcengine.inc" + + + .export _clrscr +_clrscr: + + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 + + st0 #VDC_VWR + ldy #$40 +rowloop: ldx #$80 +colloop: + lda #' ' + staio VDC_DATA_LO + lda #$02 + staio VDC_DATA_HI + + dex + bne colloop + dey + bne rowloop + + rts + diff --git a/libsrc/pcengine/color.s b/libsrc/pcengine/color.s new file mode 100644 index 000000000..8d80114fc --- /dev/null +++ b/libsrc/pcengine/color.s @@ -0,0 +1,59 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _textcolor, _bgcolor, _bordercolor + + .include "pcengine.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + +_bgcolor: + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI + + txa + rts + +_bordercolor: + lda #0 + txa + rts + + .export colors + +colors: ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray diff --git a/libsrc/pcengine/condes.s b/libsrc/pcengine/condes.s new file mode 100644 index 000000000..dd7bd30b3 --- /dev/null +++ b/libsrc/pcengine/condes.s @@ -0,0 +1,102 @@ +; +; Ullrich von Bassewitz, 20.11.2000 +; +; CC65 runtime: Support for calling module constructors/destructors +; +; The condes routine must be called with the table address in a/x and the +; size of the table in y. The current implementation limits the table size +; to 254 bytes (127 vectors) but this shouldn't be problem for now and may +; be changed later. +; +; libinit and libdone call condes with the predefined module constructor and +; destructor tables, they must be called from the platform specific startup +; code. + + + .export initlib, donelib, condes + + .import callax + .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ + .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ + + + +.code + +; -------------------------------------------------------------------------- +; Initialize library modules + +.proc initlib + + lda #<__CONSTRUCTOR_TABLE__ + ldx #>__CONSTRUCTOR_TABLE__ + ldy #<(__CONSTRUCTOR_COUNT__*2) + bne condes + rts + +.endproc + + +; -------------------------------------------------------------------------- +; Cleanup library modules + +.proc donelib + + lda #<__DESTRUCTOR_TABLE__ + ldx #>__DESTRUCTOR_TABLE__ + ldy #<(__DESTRUCTOR_COUNT__*2) + bne condes + rts + +.endproc + + +; -------------------------------------------------------------------------- +; Generic table call handler + +.proc condes + + sta getbyt+1 + stx getbyt+2 + sty index + +loop: ldy index + beq done + dey + jsr getbyt + tax + dey + jsr getbyt + sty index + jsr callax +.ifpc02 + bra loop +.else + jmp loop +.endif + +done: rts + +.endproc + + +; -------------------------------------------------------------------------- +; Data. The getbyte routine is placed in the data segment cause it's patched +; at runtime. + +.bss + +index: .byte 0 + +.data + +getbyt: +;;getbyt_: + lda $FFFF,y + rts + +;; callax doesnt work? why?! +;_callax: +; sta @l+1 +; stx @l+2 +;@l: jmp $dead diff --git a/libsrc/pcengine/conio.s b/libsrc/pcengine/conio.s new file mode 100644 index 000000000..3c4919e64 --- /dev/null +++ b/libsrc/pcengine/conio.s @@ -0,0 +1,122 @@ + .include "pcengine.inc" + .import vce_init + .import psg_init + .import vdc_init + + .export initconio + .export _conio_init + + .constructor initconio, 24 + + .macpack longbranch +initconio: + ;; jsr vdc_init + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette + + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts + + .import colors +set_palette: + + ; Make palette (use VGA palette?) + ; stz VCE_ADDR_LO + ; stz VCE_ADDR_HI + ; clx + ; cly + vce_loop: ;; stx VCE_DATA_LO + ;; sty VCE_DATA_HI + ; inx + ; cpx #$00 + ; bne vce_loop + ; iny + ; cpy #$02 + ; bne vce_loop + + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + + ldx #0 +@lp: + .repeat 16 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + .endrepeat + + inx + inx + cpx #16*2;*5 + jne @lp + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI + +; so it will get linked in +_conio_init: + rts + +;---------------------------------------------------------------------------- +; +;---------------------------------------------------------------------------- + + .importzp ptr1 + +conio_init: + + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 + + ; ptr to font data + lda #font + sta ptr1+1 + + st0 #VDC_VWR ; VWR + ldy #$80 ; 128 chars + charloop: ldx #$08 ; 8 bytes/char + lineloop: + ;;lda [$00] ; read font byte + ldaind ptr1 + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 + + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 + fillloop: st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character + + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR + + + rts + + .rodata +font: .include "vga.inc" diff --git a/libsrc/pcengine/cputc.s b/libsrc/pcengine/cputc.s new file mode 100644 index 000000000..8a02a3499 --- /dev/null +++ b/libsrc/pcengine/cputc.s @@ -0,0 +1,117 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + + .importzp tmp3,tmp4 + + .include "pcengine.inc" + + +_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + ldy CURS_X + iny + cpy #xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot + ;rts + +newline: +; lda #xsize +; clc +; adc SCREEN_PTR +; sta SCREEN_PTR +; bcc L4 +; inc SCREEN_PTR+1 +;; clc +;L4:; lda #xsize + ; adc CRAM_PTR + ; sta CRAM_PTR + ; bcc L5 + ; inc CRAM_PTR+1 +;L5: + + inc CURS_Y + +; jmp plot +; rts + +; Set cursor position, calculate RAM pointers + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + + ora RVS ; Set revers bit + + tax + + st0 #VDC_MAWR ; Memory Adress Write + + lda SCREEN_PTR + staio VDC_DATA_LO + + lda SCREEN_PTR+1 + staio VDC_DATA_HI + + st0 #VDC_VWR ; VWR + + txa + staio VDC_DATA_LO ; character + + ;;st2 #$32 ; attrib ?! + lda CHARCOLOR + + ;;lda #2 + asl a + asl a + asl a + asl a + + and #$f0 + ora #$02 + staio VDC_DATA_HI + + rts diff --git a/libsrc/pcengine/crt0.s b/libsrc/pcengine/crt0.s new file mode 100644 index 000000000..d9c5a2ccb --- /dev/null +++ b/libsrc/pcengine/crt0.s @@ -0,0 +1,233 @@ +; +; Startup code for cc65 (PCEngine version) +; +; by Groepaz/Hitmen +; based on code by Ullrich von Bassewitz +; +; This must be the *first* file on the linker command line +; + + .export _exit + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 + + .import __RAM_START__, __RAM_SIZE__ ; Linker generated +;; .import __SRAM_START__, __SRAM_SIZE__ ; Linker generated + .import __ROM0_START__, __ROM0_SIZE__ ; Linker generated + .import __ROM_START__, __ROM_SIZE__ ; Linker generated + .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ ; Linker generated + .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ ; Linker generated + .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ ; Linker generated + .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated + .import __BSS_SIZE__ + + .include "pcengine.inc" + + .importzp sp + .importzp ptr1,ptr2 + +; ------------------------------------------------------------------------ +; Create an empty LOWCODE segment to avoid linker warnings + +.segment "LOWCODE" + +; ------------------------------------------------------------------------ +; Place the startup code in a special segment. + +.segment "STARTUP" + +start: + +; setup the CPU and System-IRQ + + ; Initialize CPU + + sei + nop + csh + nop + cld + nop + + ; Setup stack and memory mapping + ldx #$FF ; Stack top ($21FF) + txs + txa + tam #0 ; 0000-1FFF = Hardware page + + lda #$F8 + tam #1 ; 2000-3FFF = Work RAM + + lda #$F7 + tam #2 ; 4000-5FFF = Save RAM + + lda #1 + tam #3 ; 6000-7FFF Page 2 + lda #2 + tam #4 ; 8000-9FFF Page 3 + lda #3 + tam #5 ; A000-BFFF Page 4 + lda #4 + tam #6 ; C000-DFFF Page 5 + + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer + + ; Clear work RAM + stz <$00 + tii $2000, $2001, $1FFF + + ;; i dont know why the heck this one doesnt + ;; work when called from a constructor :/ + .import vdc_init + jsr vdc_init +;; jsr joy_init + + ; Turn on background and VD interrupt/IRQ1 + lda #$05 + sta IRQ_MASK ; IRQ1=on + cli + +; Clear the BSS data + + jsr zerobss + +; Copy the .data segment to RAM + + lda #<(__DATA_LOAD__) + ;;lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__) + ;;lda #<(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) + sta ptr1 + lda #>(__DATA_LOAD__) + ;;lda #>(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) + sta ptr1+1 + lda #<(__DATA_RUN__) + ;;lda #<(__SRAM_START__) + sta ptr2 + lda #>(__DATA_RUN__) + ;;lda #>(__SRAM_START__) + sta ptr2+1 + + ldx #>(__DATA_SIZE__) + +@l2: + beq @s1 ; no more full pages + + ; copy one page + ldy #0 +@l1: + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 + + inc ptr1+1 + inc ptr2+1 + + dex + bne @l2 + + ; copy remaining bytes +@s1: + + ; copy one page + ldy #0 +@l3: + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 + +; setup the stack + +; lda #<(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp +; lda #>(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 ; Set argument stack ptr + +; Init the Heap + jsr initheap + +;jmp * + +; Call module constructors + + jsr initlib +; .import initconio +; jsr initconio +; Pass an empty command line + + +;jmp * + + jsr push0 ; argc + jsr push0 ; argv +go: + ldy #4 ; Argument size + jsr _main ; call the users code + +; Call module destructors. This is also the _exit entry. + +_exit: + jsr donelib ; Run module destructors + +; reset the PCEngine + + jmp start + +; ------------------------------------------------------------------------ +; System V-Blank Interupt +; ------------------------------------------------------------------------ + +_irq1: + pha + phx + phy + + + inc _tickcount + bne @s + inc _tickcount+1 +@s: + + ; Acknowlege interrupt + ldaio VDC_CTRL + + ply + plx + pla + rti +_irq2: + rti +_nmi: + rti +_timer: + stz IRQ_STATUS + rti + + .export initmainargs +initmainargs: + rts + +; ------------------------------------------------------------------------ +; hardware vectors +; ------------------------------------------------------------------------ + .segment "VECTORS" + ;;.org $fff6 + + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset + + + diff --git a/libsrc/pcengine/huc6280.inc b/libsrc/pcengine/huc6280.inc new file mode 100644 index 000000000..ab634a855 --- /dev/null +++ b/libsrc/pcengine/huc6280.inc @@ -0,0 +1,238 @@ + +; +; HuC6280 additional opcodes (use with --cpu 65C02) +; +; WARNING: THIS IS __NOT__ COMPLETE !!! +; + +;; lda abs +.macro ldaio arg1 + .byte $ad + .word arg1 +.endmacro +;; sta abs +.macro staio arg1 + .byte $8d + .word arg1 +.endmacro +.macro stzio arg1 + .byte $9c + .word arg1 +.endmacro + +.macro cla + .byte $62 +.endmacro +.macro clx + .byte $82 +.endmacro + +;; lda (zp) +.macro ldaind arg1 + .byte $b2 + .byte arg1 +.endmacro + +.macro cly + .byte $c2 +.endmacro + +.macro st0 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $03 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro +.macro st1 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $13 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro +.macro st2 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $23 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro + +; tam #$xx +.macro tam arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $53 + .byte 1<<(.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro + +; tii x,y,z +.macro tii arg1,arg2,arg3 + .byte $73 + .word arg1,arg2,arg3 +.endmacro + +.macro csh + .byte $d4 +.endmacro +.macro set + .byte $f4 +.endmacro +.macro _rmb0 arg1 + .byte $07 + .byte arg1 +.endmacro +.macro _rmb1 arg1 + .byte $17 + .byte arg1 +.endmacro +.macro _rmb2 arg1 + .byte $27 + .byte arg1 +.endmacro +.macro _rmb3 arg1 + .byte $37 + .byte arg1 +.endmacro +.macro _rmb4 arg1 + .byte $47 + .byte arg1 +.endmacro +.macro _rmb5 arg1 + .byte $57 + .byte arg1 +.endmacro +.macro _rmb6 arg1 + .byte $67 + .byte arg1 +.endmacro +.macro _rmb7 arg1 + .byte $77 + .byte arg1 +.endmacro + +.macro _smb0 arg1 + .byte $87 + .byte arg1 +.endmacro +.macro _smb1 arg1 + .byte $97 + .byte arg1 +.endmacro +.macro _smb2 arg1 + .byte $a7 + .byte arg1 +.endmacro +.macro _smb3 arg1 + .byte $b7 + .byte arg1 +.endmacro +.macro _smb4 arg1 + .byte $c7 + .byte arg1 +.endmacro +.macro _smb5 arg1 + .byte $d7 + .byte arg1 +.endmacro +.macro _smb6 arg1 + .byte $e7 + .byte arg1 +.endmacro +.macro _smb7 arg1 + .byte $f7 + .byte arg1 +.endmacro + +.macro _bbr0 arg1,arg2 + .byte $0f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs0 arg1,arg2 + .byte $8f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr1 arg1,arg2 + .byte $1f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs1 arg1,arg2 + .byte $9f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr2 arg1,arg2 + .byte $2f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs2 arg1,arg2 + .byte $af ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr3 arg1,arg2 + .byte $3f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs3 arg1,arg2 + .byte $bf ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr4 arg1,arg2 + .byte $4f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs4 arg1,arg2 + .byte $cf ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr5 arg1,arg2 + .byte $5f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs5 arg1,arg2 + .byte $df ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr6 arg1,arg2 + .byte $6f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs6 arg1,arg2 + .byte $ef ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr7 arg1,arg2 + .byte $7f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs7 arg1,arg2 + .byte $ff + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro + + diff --git a/libsrc/pcengine/joytokbd.s b/libsrc/pcengine/joytokbd.s new file mode 100644 index 000000000..1e8258e08 --- /dev/null +++ b/libsrc/pcengine/joytokbd.s @@ -0,0 +1,275 @@ +; +; File generated by cc65 v 2.9.5 +; + .fopt compiler,"cc65 v 2.9.5" + .autoimport on + .case on + .debuginfo off + .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 + .macpack longbranch + .import _joy_masks + .import _joy_read + .import _clock + .export _kbhit + .export _cgetc + +.segment "DATA" + +__lastkey: + .byte $00 +__chardelay: + .dword $00000000 +_rptkey: + .byte $00 + +; --------------------------------------------------------------- +; void _getkey (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc __getkey + +.segment "CODE" + + jsr decsp2 + ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L003F + lda #$00 + jsr _joy_read + ldy #$01 + sta (sp),y + ldx #$00 + lda #$00 + ldy #$00 + sta (sp),y + ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+4 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0010 + ldx #$00 + lda #$0A + ldy #$00 + sta (sp),y + jmp L003A +L0010: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0016 + ldx #$00 + lda #$01 + ldy #$00 + sta (sp),y + jmp L003A +L0016: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+2 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L001C + ldx #$00 + lda #$03 + ldy #$00 + sta (sp),y + jmp L003A +L001C: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+3 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0022 + ldx #$00 + lda #$04 + ldy #$00 + sta (sp),y + jmp L003A +L0022: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+1 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0028 + ldx #$00 + lda #$02 + ldy #$00 + sta (sp),y + jmp L003A +L0028: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+7 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L002E + ldx #$00 + lda #$14 + ldy #$00 + sta (sp),y + jmp L003A +L002E: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+5 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0034 + ldx #$00 + lda #$15 + ldy #$00 + sta (sp),y + jmp L003A +L0034: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+6 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L003A + ldx #$00 + lda #$16 + ldy #$00 + sta (sp),y +L003A: ldy #$00 + ldx #$00 + lda (sp),y + cmp #$00 + jsr boolne + jeq L003F + ldy #$00 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _rptkey + jsr toseqax + jeq L0043 + lda __chardelay+3 + sta sreg+1 + lda __chardelay+2 + sta sreg + ldx __chardelay+1 + lda __chardelay + jsr pusheax + jsr _clock + jsr tosugteax + jeq L0043 + jmp L003F +L0043: ldy #$00 + ldx #$00 + lda (sp),y + sta _rptkey + jsr _clock + ldy #$06 + jsr inceaxy + sta __chardelay + stx __chardelay+1 + ldy sreg + sty __chardelay+2 + ldy sreg+1 + sty __chardelay+3 + ldy #$00 + ldx #$00 + lda (sp),y + sta __lastkey +L003F: jsr incsp2 + rts + +.endproc + +; --------------------------------------------------------------- +; unsigned char __fastcall__ kbhit (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _kbhit + +.segment "CODE" + + jsr __getkey + ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L004E + ldx #$00 + lda #$00 + jmp L0052 + jmp L0052 +L004E: ldx #$00 + lda #$01 + jmp L0052 +L0052: rts + +.endproc + +; --------------------------------------------------------------- +; unsigned char __fastcall__ cgetc (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _cgetc + +.segment "CODE" + + jsr decsp1 +L0056: ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L0057 + jsr __getkey + jmp L0056 +L0057: ldx #$00 + lda __lastkey + ldy #$00 + sta (sp),y + ldx #$00 + lda #$00 + sta __lastkey + ldy #$00 + ldx #$00 + lda (sp),y + jmp L0055 +L0055: jsr incsp1 + rts + +.endproc + diff --git a/libsrc/pcengine/kplot.s b/libsrc/pcengine/kplot.s new file mode 100644 index 000000000..f050d78ef --- /dev/null +++ b/libsrc/pcengine/kplot.s @@ -0,0 +1,41 @@ + + .export PLOT + + .include "pcengine.inc" + +PLOT: + + bcs @getpos + + tya + clc + adc _plotlo,x + sta SCREEN_PTR + + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 + + ;clc + ;adc _colplot,x + ;sta CRAM_PTR + + ;lda #$23 + ;sta CRAM_PTR+1 + +@getpos: + ldx CURS_Y + ldy CURS_X + rts + +_plotlo: + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat + +_plothi: + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat + + diff --git a/libsrc/pcengine/pce-stdjoy.s b/libsrc/pcengine/pce-stdjoy.s new file mode 100644 index 000000000..60c77db1e --- /dev/null +++ b/libsrc/pcengine/pce-stdjoy.s @@ -0,0 +1,191 @@ + +; +; Standard joystick driver for the PCEngine +; +; Ullrich von Bassewitz, 2002-12-20 +; + + ;;.include "zeropage.inc" + + ;;.include "joy-kernel.inc" + + ;;.include "joy-error.inc" + JOY_ERR_OK=0; + .include "pcengine.inc" + + .macpack generic + +; ------------------------------------------------------------------------ +; Header. Includes jump table + +.segment "CODE" + +; Driver signature + +;; .byte $6A, $6F, $79 ; "joy" +;; .byte $00 ; Driver API version number + +; Button state masks (8 values) + +;extern const unsigned char joy_masks[8]; + + .export _joy_masks + +_joy_masks: + .byte $10 ; JOY_UP + .byte $40 ; JOY_DOWN + .byte $80 ; JOY_LEFT + .byte $20 ; JOY_RIGHT + .byte $04 ; ? JOY_FIRE + .byte $02 ; ? Future expansion + .byte $01 ; ? Future expansion + .byte $08 ; ? Future expansion + +; Jump table. + +;; .word INSTALL +;; .word DEINSTALL +;; .word COUNT +;; .word READ + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 4 ; Number of joysticks we support + + +; ------------------------------------------------------------------------ +; Data. + + +.code + + +;extern const char joy_stddrv[]; + + .export _joy_stddrv +_joy_stddrv: + .byte 0 + + + .export _joy_load_driver + .export _joy_unload + +;unsigned char __fastcall__ joy_unload (void); +;unsigned char __fastcall__ joy_load_driver (const char* driver); +_joy_load_driver: +_joy_unload: + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #JOY_ERR_OK + +; rts ; Run into DEINSTALL instead + +; ------------------------------------------------------------------------ +; DEINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +DEINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; +;unsigned char __fastcall__ joy_count (void); + + .export _joy_count + +_joy_count: +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +;unsigned char __fastcall__ joy_read (unsigned char joystick); + + .export _joy_read + +_joy_read: +READ: + pha + jsr read_joy + pla + tax ; Joystick number into X + + ; return value from buffer + +joy1: + lda padbuffer,x + ldx #0 + rts + +.code + +read_joy: + ; reset multitap counter + lda #$01 + sta $1000 + pha + pla + nop + nop + + lda #$03 + sta $1000 + pha + pla + nop + nop + + cly +nextpad: + lda #$01 + sta $1000 ; sel = 1 + pha + pla + nop + nop + + lda $1000 + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value + + stz $1000 + pha + pla + nop + nop + + lda $1000 + and #$0F + ora padbuffer, y ; second half of new value + + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts + +.bss + +padbuffer: + .res 4 + diff --git a/libsrc/pcengine/pcengine.h b/libsrc/pcengine/pcengine.h new file mode 100644 index 000000000..8135679a2 --- /dev/null +++ b/libsrc/pcengine/pcengine.h @@ -0,0 +1,74 @@ +#define CH_CROSS 0x10 + +#define CH_RTEE 0x17 +#define CH_LTEE 0x0f + +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x10 +#define CH_LLCORNER 0x10 +#define CH_LRCORNER 0x10 + + +#define TV_NTSC 0 +#define TV_PAL 1 +#define get_tv() 0 + +#define CLOCKS_PER_SEC 50 // ??? +#define CLK_TCK 50 // ?!? + +//#ifndef CH_ENTER +#define CH_ENTER '\n' +//#endif + +#define CH_STOP 0x08 + +#define CH_F1 0x14 +#define CH_F3 0x15 +#define CH_F5 0x16 +#define CH_F7 0x17 + +#define CH_CURS_UP 0x01 +#define CH_CURS_DOWN 0x02 + +#ifndef CH_CURS_LEFT +#define CH_CURS_LEFT 0x03 +#endif + +#ifndef CH_CURS_RIGHT +#define CH_CURS_RIGHT 0x04 +#endif + +#define CH_ESC 8 + +#define CH_DEL 20 + +/* Color defines */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +#define JOY_FIRE_B 5 +#define JOY_START 6 +#define JOY_SELECT 7 + +/* +void __fastcall__ waitvblank(void); + +unsigned char __fastcall__ cpeekcharxy(unsigned char x,unsigned char y); +unsigned char __fastcall__ cpeekchar(void); +unsigned char __fastcall__ cpeekcolxy(unsigned char x,unsigned char y); +unsigned char __fastcall__ cpeekcol(void); +*/ diff --git a/libsrc/pcengine/pcengine.inc b/libsrc/pcengine/pcengine.inc new file mode 100644 index 000000000..ec61d9153 --- /dev/null +++ b/libsrc/pcengine/pcengine.inc @@ -0,0 +1,75 @@ + + .include "huc6280.inc" + +; Write VDC register + .macro VREG arg1,arg2 + st0 #arg1 + st1 #<(arg2) + st2 #>(arg2) + .endmacro + +_tickcount= $20 + +screenrows = (224/8) +charsperline = (512/8) +xsize = charsperline + +CH_HLINE = 7 +CH_VLINE = 7 + +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 +CRAM_PTR = $34 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR=$38 + +; huc6270 - Video Display Controller (vdc) + +VDC_MAWR = 0 ; Memory Address Write Register +VDC_MARR = 1 ; Memory Address Read Register +VDC_VWR = 2 ; VRAM Write Register +VDC_VRR = 3 ; VRAM Read Register +VDC_CR = 4 ; Control Register +VDC_RCR = 5 ; Raster Counter Register +VDC_BXR = 6 ; Background X-Scroll Register +VDC_BYR = 7 ; Background Y-Scroll Register +VDC_MWR = 8 ; Memory-access Width Register +VDC_HSR = 9 ; Horizontal Sync Register (?) +VDC_HDR =10 ; Horizontal Display Register (?) +VDC_VPR =11 ; (unknown) +VDC_VDW =12 ; (unknown use) +VDC_VCR =13 ; (unknown use) +VDC_DCR =14 ; (DMA) Control Register +VDC_SOUR =15 ; (DMA) Source Register +VDC_DESR =16 ; (DMA) Destination Register +VDC_LENR =17 ; (DMA) Length Register +VDC_SATB =18 ; Sprite Attribute Table + +VDC_CTRL = $0000 +VDC_DATA_LO = $0002 +VDC_DATA_HI = $0003 + +; huc6260 - Video Color Encoder (vce) + +; The DAC has a palette of 512 colours. +; bitmap of the palette data is this: 0000000gggrrrbbb. +; You can read and write the DAC-registers. + +VCE_CTRL = $0400 ; write$00 to reset +VCE_ADDR_LO = $0402 ; LSB of byte offset into palette +VCE_ADDR_HI = $0403 ; MSB of byte offset into palette +VCE_DATA_LO = $0404 ; LSB of 16-bit palette data +VCE_DATA_HI = $0405 ; MSB of 16-bit palette data + +TIMER_COUNT = $0c00 +TIMER_CTRL = $0c01 + +JOY_CTRL = $1000 + +IRQ_MASK = $1402 +IRQ_STATUS = $1403 + +CDR_MEM_DISABLE = $1803 +CDR_MEM_ENABLE = $1807 \ No newline at end of file diff --git a/libsrc/pcengine/pcengine.x b/libsrc/pcengine/pcengine.x new file mode 100644 index 000000000..276f3b3b6 --- /dev/null +++ b/libsrc/pcengine/pcengine.x @@ -0,0 +1,68 @@ +MEMORY { + + ZP: start = $00, size = $1A, type = rw, define = yes; + + # INES Cartridge Header + #HEADER: start = $0, size = $10, file = %O ,fill = yes; + + # 2 16K ROM Banks + # - startup + # - code + # - rodata + # - data (load) + # 1 8k CHR Bank + ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; + # Hardware Vectors at End of 2nd 8K ROM + ROMV: start = $fff6, size = $a, file = %O,fill = yes; + + ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; + + + # standard 2k SRAM (-zeropage) + # $0100-$0200 cpu stack + # $0200-$0500 3 pages for ppu memory write buffer + # $0500-$0800 3 pages for cc65 parameter stack + #SRAM: start = $0500, size = $0300, define = yes; + + # additional 8K SRAM Bank + # - data (run) + # - bss + # - heap +# RAM: start = $2200, size = $1000, define = yes; +# RAM2: start = $3200, size = $0e00, define = yes; + RAM: start = $2200, size = $1e00, define = yes; + +} +SEGMENTS { + #HEADER: load = HEADER, type = wprot; + + #aSTARTUP: load = ROM0, type = wprot, define = yes; + STARTUP: load = ROM0, type = wprot, define = yes; + + CODE: load = ROM, type = wprot, define = yes; + RODATA: load = ROM, type = wprot, define = yes; + + DATA: load = ROM0, run= RAM, type = rw, define = yes; +# BSS: load = RAM2, type = bss, define = yes; + BSS: load = RAM, type = bss, define = yes; + + VECTORS: load = ROMV, type = rw, define = yes; + #CHARS: load = ROM2, type = rw; + + + ZEROPAGE: load = ZP, type = zp, define = yes; + +} +FEATURES { + CONDES: segment = STARTUP, + type=constructor, + label=__CONSTRUCTOR_TABLE__, + count=__CONSTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type=destructor, + label=__DESTRUCTOR_TABLE__, + count=__DESTRUCTOR_COUNT__; +} +SYMBOLS { + __STACKSIZE__ = $0300; # 3 pages stack +} diff --git a/libsrc/pcengine/psg.s b/libsrc/pcengine/psg.s new file mode 100644 index 000000000..ebf35d952 --- /dev/null +++ b/libsrc/pcengine/psg.s @@ -0,0 +1,29 @@ + + .include "pcengine.inc" + + .export psg_init + +psg_init: + clx + stx $0800 ; Select channel +psg_clear_loop: + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control + + cly +psg_clear_waveform: stz $0806 ; Clear waveform byte + iny + cpy #$20 + bne psg_clear_waveform + + inx + cpx #$06 + bne psg_clear_loop + rts + diff --git a/libsrc/pcengine/revers.s b/libsrc/pcengine/revers.s new file mode 100644 index 000000000..d1358a52b --- /dev/null +++ b/libsrc/pcengine/revers.s @@ -0,0 +1,5 @@ + + .export _revers +_revers: + lda #0 + rts diff --git a/libsrc/pcengine/vce.s b/libsrc/pcengine/vce.s new file mode 100644 index 000000000..a5c919970 --- /dev/null +++ b/libsrc/pcengine/vce.s @@ -0,0 +1,16 @@ + + .include "pcengine.inc" + .export vce_init + +vce_init: + stz VCE_ADDR_LO ; + stz VCE_ADDR_HI ; Set CTA to zero + ldy #$01 +vce_clear_bank: ldx #$00 +vce_clear_color: stz VCE_DATA_LO ; Clear color (LSB) + stz VCE_DATA_HI ; Clear color (MSB) + dex + bne vce_clear_color + dey + bne vce_clear_bank + rts diff --git a/libsrc/pcengine/vdc.s b/libsrc/pcengine/vdc.s new file mode 100644 index 000000000..a203cb058 --- /dev/null +++ b/libsrc/pcengine/vdc.s @@ -0,0 +1,46 @@ + + .include "pcengine.inc" + +HIRES = 1 + + .export vdc_init + +vdc_init: + ;;lda $0000 + ;;.byte $ad,0,0 + + ldaio VDC_CTRL + + VREG $00, $0000 ; MAWR + VREG $01, $0000 ; MARR + VREG $05, $0000 ; CR + VREG $06, $0000 ; RCR + VREG $07, $0000 ; BXR + VREG $08, $0000 ; BYR + VREG $09, $0070 ; MAWR + VREG $0C, $1702 ; CRTC - VSR + VREG $0D, $00DF ; CRTC - VDS + VREG $0E, $000C ; CRTC - VDE + VREG $0F, $0000 ; DCR + + .if HIRES + + VREG $0A, $0C02 ; CRTC - HSR + VREG $0B, $043C ; CRTC - HDS + lda #$06 + sta VCE_CTRL + + .else + + VREG $0A, $0202 ; CRTC - HSR + VREG $0B, $041F ; CRTC - HDS + lda #$04 + sta VCE_CTRL + + .endif + + ;;lda $0000 + ;;.byte $ad,0,0 + + ldaio VDC_CTRL + rts diff --git a/libsrc/pcengine/vga.inc b/libsrc/pcengine/vga.inc new file mode 100644 index 000000000..6cbdd010c --- /dev/null +++ b/libsrc/pcengine/vga.inc @@ -0,0 +1,129 @@ + + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 + .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 + .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 + .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 + .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 + .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 + .byte $66, $66, $66, $66, $66, $00, $66, $00 + .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 + .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 + .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 + .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF + .byte $18, $3C, $7E, $18, $18, $18, $18, $00 + .byte $18, $18, $18, $18, $7E, $3C, $18, $00 + .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 + .byte $00, $30, $60, $FE, $60, $30, $00, $00 + .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 + .byte $00, $24, $66, $FF, $66, $24, $00, $00 + .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 + .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $30, $78, $78, $78, $30, $00, $30, $00 + .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 + .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 + .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 + .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 + .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 + .byte $60, $60, $C0, $00, $00, $00, $00, $00 + .byte $18, $30, $60, $60, $60, $30, $18, $00 + .byte $60, $30, $18, $18, $18, $30, $60, $00 + .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 + .byte $00, $30, $30, $FC, $30, $30, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $60 + .byte $00, $00, $00, $FC, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $00 + .byte $06, $0C, $18, $30, $60, $C0, $80, $00 + .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 + .byte $30, $70, $30, $30, $30, $30, $FC, $00 + .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 + .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 + .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 + .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 + .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 + .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 + .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 + .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $60 + .byte $18, $30, $60, $C0, $60, $30, $18, $00 + .byte $00, $00, $FC, $00, $00, $FC, $00, $00 + .byte $60, $30, $18, $0C, $18, $30, $60, $00 + .byte $78, $CC, $0C, $18, $30, $00, $30, $00 + .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 + .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 + .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 + .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 + .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 + .byte $7E, $60, $60, $78, $60, $60, $7E, $00 + .byte $7E, $60, $60, $78, $60, $60, $60, $00 + .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 + .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 + .byte $78, $30, $30, $30, $30, $30, $78, $00 + .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 + .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 + .byte $60, $60, $60, $60, $60, $60, $7E, $00 + .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 + .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 + .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 + .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 + .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 + .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 + .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 + .byte $FC, $30, $30, $30, $30, $30, $30, $00 + .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 + .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 + .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 + .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 + .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 + .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 + .byte $78, $60, $60, $60, $60, $60, $78, $00 + .byte $C0, $60, $30, $18, $0C, $06, $02, $00 + .byte $78, $18, $18, $18, $18, $18, $78, $00 + .byte $10, $38, $6C, $C6, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $FF + .byte $30, $30, $18, $00, $00, $00, $00, $00 + .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 + .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 + .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 + .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 + .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 + .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 + .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 + .byte $30, $00, $70, $30, $30, $30, $78, $00 + .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 + .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 + .byte $70, $30, $30, $30, $30, $30, $78, $00 + .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 + .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 + .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 + .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E + .byte $00, $00, $DC, $76, $66, $60, $F0, $00 + .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 + .byte $10, $30, $7C, $30, $30, $34, $18, $00 + .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 + .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 + .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 + .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 + .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 + .byte $00, $00, $FC, $98, $30, $64, $FC, $00 + .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 + .byte $18, $18, $18, $00, $18, $18, $18, $00 + .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 + .byte $76, $DC, $00, $00, $00, $00, $00, $00 + .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 From 86e6abfcd946ec5bf19879f3d8a48e2a4807e506 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sat, 29 Nov 2014 15:13:40 +0100 Subject: [PATCH 02/28] added compiler/assembler target, lib compiles --- libsrc/{pcengine => pce}/_heap.s | 0 libsrc/{pcengine => pce}/_scrsize.s | 0 libsrc/{pcengine => pce}/call.s | 0 libsrc/{pcengine => pce}/clock.s | 0 libsrc/{pcengine => pce}/clrscr.s | 0 libsrc/{pcengine => pce}/color.s | 0 libsrc/{pcengine => pce}/condes.s | 0 libsrc/{pcengine => pce}/conio.s | 0 libsrc/{pcengine => pce}/cputc.s | 0 libsrc/{pcengine => pce}/crt0.s | 0 libsrc/{pcengine => pce}/huc6280.inc | 0 libsrc/{pcengine => pce}/joytokbd.s | 0 libsrc/{pcengine => pce}/kplot.s | 0 libsrc/{pcengine => pce}/pce-stdjoy.s | 0 libsrc/{pcengine => pce}/pcengine.h | 0 libsrc/{pcengine => pce}/pcengine.inc | 0 libsrc/{pcengine => pce}/pcengine.x | 0 libsrc/{pcengine => pce}/psg.s | 0 libsrc/{pcengine => pce}/revers.s | 0 libsrc/{pcengine => pce}/vce.s | 0 libsrc/{pcengine => pce}/vdc.s | 0 libsrc/{pcengine => pce}/vga.inc | 0 22 files changed, 0 insertions(+), 0 deletions(-) rename libsrc/{pcengine => pce}/_heap.s (100%) rename libsrc/{pcengine => pce}/_scrsize.s (100%) rename libsrc/{pcengine => pce}/call.s (100%) rename libsrc/{pcengine => pce}/clock.s (100%) rename libsrc/{pcengine => pce}/clrscr.s (100%) rename libsrc/{pcengine => pce}/color.s (100%) rename libsrc/{pcengine => pce}/condes.s (100%) rename libsrc/{pcengine => pce}/conio.s (100%) rename libsrc/{pcengine => pce}/cputc.s (100%) rename libsrc/{pcengine => pce}/crt0.s (100%) rename libsrc/{pcengine => pce}/huc6280.inc (100%) rename libsrc/{pcengine => pce}/joytokbd.s (100%) rename libsrc/{pcengine => pce}/kplot.s (100%) rename libsrc/{pcengine => pce}/pce-stdjoy.s (100%) rename libsrc/{pcengine => pce}/pcengine.h (100%) rename libsrc/{pcengine => pce}/pcengine.inc (100%) rename libsrc/{pcengine => pce}/pcengine.x (100%) rename libsrc/{pcengine => pce}/psg.s (100%) rename libsrc/{pcengine => pce}/revers.s (100%) rename libsrc/{pcengine => pce}/vce.s (100%) rename libsrc/{pcengine => pce}/vdc.s (100%) rename libsrc/{pcengine => pce}/vga.inc (100%) diff --git a/libsrc/pcengine/_heap.s b/libsrc/pce/_heap.s similarity index 100% rename from libsrc/pcengine/_heap.s rename to libsrc/pce/_heap.s diff --git a/libsrc/pcengine/_scrsize.s b/libsrc/pce/_scrsize.s similarity index 100% rename from libsrc/pcengine/_scrsize.s rename to libsrc/pce/_scrsize.s diff --git a/libsrc/pcengine/call.s b/libsrc/pce/call.s similarity index 100% rename from libsrc/pcengine/call.s rename to libsrc/pce/call.s diff --git a/libsrc/pcengine/clock.s b/libsrc/pce/clock.s similarity index 100% rename from libsrc/pcengine/clock.s rename to libsrc/pce/clock.s diff --git a/libsrc/pcengine/clrscr.s b/libsrc/pce/clrscr.s similarity index 100% rename from libsrc/pcengine/clrscr.s rename to libsrc/pce/clrscr.s diff --git a/libsrc/pcengine/color.s b/libsrc/pce/color.s similarity index 100% rename from libsrc/pcengine/color.s rename to libsrc/pce/color.s diff --git a/libsrc/pcengine/condes.s b/libsrc/pce/condes.s similarity index 100% rename from libsrc/pcengine/condes.s rename to libsrc/pce/condes.s diff --git a/libsrc/pcengine/conio.s b/libsrc/pce/conio.s similarity index 100% rename from libsrc/pcengine/conio.s rename to libsrc/pce/conio.s diff --git a/libsrc/pcengine/cputc.s b/libsrc/pce/cputc.s similarity index 100% rename from libsrc/pcengine/cputc.s rename to libsrc/pce/cputc.s diff --git a/libsrc/pcengine/crt0.s b/libsrc/pce/crt0.s similarity index 100% rename from libsrc/pcengine/crt0.s rename to libsrc/pce/crt0.s diff --git a/libsrc/pcengine/huc6280.inc b/libsrc/pce/huc6280.inc similarity index 100% rename from libsrc/pcengine/huc6280.inc rename to libsrc/pce/huc6280.inc diff --git a/libsrc/pcengine/joytokbd.s b/libsrc/pce/joytokbd.s similarity index 100% rename from libsrc/pcengine/joytokbd.s rename to libsrc/pce/joytokbd.s diff --git a/libsrc/pcengine/kplot.s b/libsrc/pce/kplot.s similarity index 100% rename from libsrc/pcengine/kplot.s rename to libsrc/pce/kplot.s diff --git a/libsrc/pcengine/pce-stdjoy.s b/libsrc/pce/pce-stdjoy.s similarity index 100% rename from libsrc/pcengine/pce-stdjoy.s rename to libsrc/pce/pce-stdjoy.s diff --git a/libsrc/pcengine/pcengine.h b/libsrc/pce/pcengine.h similarity index 100% rename from libsrc/pcengine/pcengine.h rename to libsrc/pce/pcengine.h diff --git a/libsrc/pcengine/pcengine.inc b/libsrc/pce/pcengine.inc similarity index 100% rename from libsrc/pcengine/pcengine.inc rename to libsrc/pce/pcengine.inc diff --git a/libsrc/pcengine/pcengine.x b/libsrc/pce/pcengine.x similarity index 100% rename from libsrc/pcengine/pcengine.x rename to libsrc/pce/pcengine.x diff --git a/libsrc/pcengine/psg.s b/libsrc/pce/psg.s similarity index 100% rename from libsrc/pcengine/psg.s rename to libsrc/pce/psg.s diff --git a/libsrc/pcengine/revers.s b/libsrc/pce/revers.s similarity index 100% rename from libsrc/pcengine/revers.s rename to libsrc/pce/revers.s diff --git a/libsrc/pcengine/vce.s b/libsrc/pce/vce.s similarity index 100% rename from libsrc/pcengine/vce.s rename to libsrc/pce/vce.s diff --git a/libsrc/pcengine/vdc.s b/libsrc/pce/vdc.s similarity index 100% rename from libsrc/pcengine/vdc.s rename to libsrc/pce/vdc.s diff --git a/libsrc/pcengine/vga.inc b/libsrc/pce/vga.inc similarity index 100% rename from libsrc/pcengine/vga.inc rename to libsrc/pce/vga.inc From 4275b82117599db211e813c1adef7c941bceed20 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sat, 29 Nov 2014 15:35:20 +0100 Subject: [PATCH 03/28] added compiler/assembler target, lib compiles --- libsrc/pce/pcengine.x => cfg/pce.cfg | 0 libsrc/Makefile | 2 +- libsrc/joystick/joy-kernel.s | 2 +- libsrc/pce/_heap.s | 67 -------- libsrc/pce/clrscr.s | 36 ++-- libsrc/pce/conio.s | 24 +-- libsrc/pce/huc6280.inc | 238 --------------------------- libsrc/pce/pcengine.inc | 21 ++- src/ca65/main.c | 4 + src/cc65/main.c | 4 + src/common/target.c | 2 + src/common/target.h | 1 + 12 files changed, 60 insertions(+), 341 deletions(-) rename libsrc/pce/pcengine.x => cfg/pce.cfg (100%) delete mode 100644 libsrc/pce/_heap.s delete mode 100644 libsrc/pce/huc6280.inc diff --git a/libsrc/pce/pcengine.x b/cfg/pce.cfg similarity index 100% rename from libsrc/pce/pcengine.x rename to cfg/pce.cfg diff --git a/libsrc/Makefile b/libsrc/Makefile index 051e5cf3a..dc944ee05 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -24,7 +24,7 @@ TARGETS = apple2 \ $(GEOS) \ lynx \ nes \ - pcengine \ + pce \ sim6502 \ sim65c02 \ supervision diff --git a/libsrc/joystick/joy-kernel.s b/libsrc/joystick/joy-kernel.s index 1ba3056d8..2b1dcf884 100644 --- a/libsrc/joystick/joy-kernel.s +++ b/libsrc/joystick/joy-kernel.s @@ -109,7 +109,7 @@ inv_drv: copy: lda (ptr1),y iny -set: sta joy_vectors,x + sta joy_vectors,x inx rts diff --git a/libsrc/pce/_heap.s b/libsrc/pce/_heap.s deleted file mode 100644 index 71fa13e78..000000000 --- a/libsrc/pce/_heap.s +++ /dev/null @@ -1,67 +0,0 @@ -; -; Ullrich von Bassewitz, 03.06.1998 -; -; Heap variables and initialization. -; - -; FIXME: there should be a way to configure heap from linkerscript! - - .constructor initheap, 24 - - .import __RAM_START__, __RAM_SIZE__, __STACKSIZE__ ; Linker generated - .import __BSS_SIZE__ - .importzp sp - -.data - -;; old - remove - .export __horg, __hptr, __hend, __hfirst, __hlast -__horg: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__hptr: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Dito -__hend: - .word __RAM_START__+__RAM_SIZE__ -__hfirst: - .word 0 -__hlast: - .word 0 - - .export __heaporg - .export __heapptr - .export __heapend - .export __heapfirst - .export __heaplast - -__heaporg: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__heapptr: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__heapend: - .word __RAM_START__+__RAM_SIZE__ -__heapfirst: - .word 0 -__heaplast: - .word 0 - - -; Initialization. Will be called from startup! - -.code - -initheap: - ;sec - ;lda sp -; lda #<(__STACKSIZE__) -; lda #<(__RAM_START__+__RAM_SIZE__) - lda #<(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) - sta __heapend - sta __hend ; old -; lda sp+1 -; lda #>(__STACKSIZE__) -; lda #>(__RAM_START__+__RAM_SIZE__) - lda #>(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) - sta __heapend+1 - sta __hend+1 ; old - rts - diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index c2c5dcbcb..0a2b8b62d 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,27 +1,25 @@ - .include "pcengine.inc" + .include "pcengine.inc" - - .export _clrscr + .export _clrscr _clrscr: - st0 #VDC_MAWR - st1 #<$0000 - st2 #>$0000 + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 - st0 #VDC_VWR - ldy #$40 -rowloop: ldx #$80 -colloop: - lda #' ' - staio VDC_DATA_LO - lda #$02 - staio VDC_DATA_HI + st0 #VDC_VWR + ldy #$40 +rowloop: ldx #$80 +colloop: lda #' ' + staio VDC_DATA_LO + lda #$02 + staio VDC_DATA_HI - dex - bne colloop - dey - bne rowloop + dex + bne colloop + dey + bne rowloop - rts + rts diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 3c4919e64..0a66cf454 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -69,27 +69,27 @@ _conio_init: ; ;---------------------------------------------------------------------------- - .importzp ptr1 + .importzp ptr1 conio_init: ; Load font - st0 #VDC_MAWR + st0 #VDC_MAWR st1 #<$2000 st2 #>$2000 ; ptr to font data - lda #font - sta ptr1+1 + lda #font + sta ptr1+1 st0 #VDC_VWR ; VWR ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: ;;lda [$00] ; read font byte - ldaind ptr1 + lda (ptr1) staio VDC_DATA_LO ; bitplane 0 stzio VDC_DATA_HI ; bitplane 1 @@ -110,13 +110,13 @@ conio_init: dey bne charloop ; next character - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR rts - .rodata + .rodata font: .include "vga.inc" diff --git a/libsrc/pce/huc6280.inc b/libsrc/pce/huc6280.inc deleted file mode 100644 index ab634a855..000000000 --- a/libsrc/pce/huc6280.inc +++ /dev/null @@ -1,238 +0,0 @@ - -; -; HuC6280 additional opcodes (use with --cpu 65C02) -; -; WARNING: THIS IS __NOT__ COMPLETE !!! -; - -;; lda abs -.macro ldaio arg1 - .byte $ad - .word arg1 -.endmacro -;; sta abs -.macro staio arg1 - .byte $8d - .word arg1 -.endmacro -.macro stzio arg1 - .byte $9c - .word arg1 -.endmacro - -.macro cla - .byte $62 -.endmacro -.macro clx - .byte $82 -.endmacro - -;; lda (zp) -.macro ldaind arg1 - .byte $b2 - .byte arg1 -.endmacro - -.macro cly - .byte $c2 -.endmacro - -.macro st0 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $03 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro -.macro st1 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $13 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro -.macro st2 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $23 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro - -; tam #$xx -.macro tam arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $53 - .byte 1<<(.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro - -; tii x,y,z -.macro tii arg1,arg2,arg3 - .byte $73 - .word arg1,arg2,arg3 -.endmacro - -.macro csh - .byte $d4 -.endmacro -.macro set - .byte $f4 -.endmacro -.macro _rmb0 arg1 - .byte $07 - .byte arg1 -.endmacro -.macro _rmb1 arg1 - .byte $17 - .byte arg1 -.endmacro -.macro _rmb2 arg1 - .byte $27 - .byte arg1 -.endmacro -.macro _rmb3 arg1 - .byte $37 - .byte arg1 -.endmacro -.macro _rmb4 arg1 - .byte $47 - .byte arg1 -.endmacro -.macro _rmb5 arg1 - .byte $57 - .byte arg1 -.endmacro -.macro _rmb6 arg1 - .byte $67 - .byte arg1 -.endmacro -.macro _rmb7 arg1 - .byte $77 - .byte arg1 -.endmacro - -.macro _smb0 arg1 - .byte $87 - .byte arg1 -.endmacro -.macro _smb1 arg1 - .byte $97 - .byte arg1 -.endmacro -.macro _smb2 arg1 - .byte $a7 - .byte arg1 -.endmacro -.macro _smb3 arg1 - .byte $b7 - .byte arg1 -.endmacro -.macro _smb4 arg1 - .byte $c7 - .byte arg1 -.endmacro -.macro _smb5 arg1 - .byte $d7 - .byte arg1 -.endmacro -.macro _smb6 arg1 - .byte $e7 - .byte arg1 -.endmacro -.macro _smb7 arg1 - .byte $f7 - .byte arg1 -.endmacro - -.macro _bbr0 arg1,arg2 - .byte $0f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs0 arg1,arg2 - .byte $8f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr1 arg1,arg2 - .byte $1f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs1 arg1,arg2 - .byte $9f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr2 arg1,arg2 - .byte $2f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs2 arg1,arg2 - .byte $af ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr3 arg1,arg2 - .byte $3f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs3 arg1,arg2 - .byte $bf ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr4 arg1,arg2 - .byte $4f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs4 arg1,arg2 - .byte $cf ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr5 arg1,arg2 - .byte $5f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs5 arg1,arg2 - .byte $df ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr6 arg1,arg2 - .byte $6f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs6 arg1,arg2 - .byte $ef ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr7 arg1,arg2 - .byte $7f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs7 arg1,arg2 - .byte $ff - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro - - diff --git a/libsrc/pce/pcengine.inc b/libsrc/pce/pcengine.inc index ec61d9153..a0ef03f6a 100644 --- a/libsrc/pce/pcengine.inc +++ b/libsrc/pce/pcengine.inc @@ -1,6 +1,4 @@ - .include "huc6280.inc" - ; Write VDC register .macro VREG arg1,arg2 st0 #arg1 @@ -72,4 +70,21 @@ IRQ_MASK = $1402 IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 -CDR_MEM_ENABLE = $1807 \ No newline at end of file +CDR_MEM_ENABLE = $1807 + + +;; lda abs +.macro ldaio arg1 + .byte $ad + .word arg1 +.endmacro +;; sta abs +.macro staio arg1 + .byte $8d + .word arg1 +.endmacro +;; stz abs +.macro stzio arg1 + .byte $9c + .word arg1 +.endmacro diff --git a/src/ca65/main.c b/src/ca65/main.c index 3f31a2b88..4f39eb286 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -303,6 +303,10 @@ static void SetSys (const char* Sys) NewSymbol ("__SIM65C02__", 1); break; + case TGT_PCENGINE: + NewSymbol ("__PCE__", 1); + break; + default: AbEnd ("Invalid target name: `%s'", Sys); diff --git a/src/cc65/main.c b/src/cc65/main.c index 34688e97e..13fe76db4 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -258,6 +258,10 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__SIM65C02__", 1); break; + case TGT_PCENGINE: + DefineNumericMacro ("__PCE__", 1); + break; + default: AbEnd ("Unknown target system type %d", Target); } diff --git a/src/common/target.c b/src/common/target.c index ffb342e25..013afe8ba 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -142,6 +142,7 @@ static const TargetEntry TargetMap[] = { { "module", TGT_MODULE }, { "nes", TGT_NES }, { "none", TGT_NONE }, + { "pce", TGT_PCENGINE }, { "pet", TGT_PET }, { "plus4", TGT_PLUS4 }, { "sim6502", TGT_SIM6502 }, @@ -180,6 +181,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "lynx", CPU_65C02, BINFMT_BINARY, CTNone }, { "sim6502", CPU_6502, BINFMT_BINARY, CTNone }, { "sim65c02", CPU_65C02, BINFMT_BINARY, CTNone }, + { "pce", CPU_HUC6280, BINFMT_BINARY, CTNone }, }; /* Target system */ diff --git a/src/common/target.h b/src/common/target.h index 72dffe382..ae9f931c4 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -77,6 +77,7 @@ typedef enum { TGT_LYNX, TGT_SIM6502, TGT_SIM65C02, + TGT_PCENGINE, TGT_COUNT /* Number of target systems */ } target_t; From 1365afa845117e44dec57e33b682abe59a3d3090 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 30 Nov 2014 11:20:57 +0100 Subject: [PATCH 04/28] more hacking --- cfg/pce.cfg | 13 +++++++------ include/conio.h | 2 ++ libsrc/pce/pcengine.h => include/pce.h | 0 libsrc/pce/clock.s | 20 ++++++++++---------- libsrc/pce/crt0.s | 1 + libsrc/pce/gotoxy.s | 19 +++++++++++++++++++ testcode/lib/conio.c | 10 ++++++++++ 7 files changed, 49 insertions(+), 16 deletions(-) rename libsrc/pce/pcengine.h => include/pce.h (100%) create mode 100644 libsrc/pce/gotoxy.s create mode 100644 testcode/lib/conio.c diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 276f3b3b6..b08e63814 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,3 +1,6 @@ +SYMBOLS { + __STACKSIZE__: type = weak, value = $0300; # 3 pages stack +} MEMORY { ZP: start = $00, size = $1A, type = rw, define = yes; @@ -37,10 +40,11 @@ SEGMENTS { #HEADER: load = HEADER, type = wprot; #aSTARTUP: load = ROM0, type = wprot, define = yes; - STARTUP: load = ROM0, type = wprot, define = yes; + STARTUP: load = ROM0, type = ro, define = yes; - CODE: load = ROM, type = wprot, define = yes; - RODATA: load = ROM, type = wprot, define = yes; + INIT: load = ROM0, type = ro, define = yes, optional = yes; + CODE: load = ROM, type = ro, define = yes; + RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM0, run= RAM, type = rw, define = yes; # BSS: load = RAM2, type = bss, define = yes; @@ -63,6 +67,3 @@ FEATURES { label=__DESTRUCTOR_TABLE__, count=__DESTRUCTOR_COUNT__; } -SYMBOLS { - __STACKSIZE__ = $0300; # 3 pages stack -} diff --git a/include/conio.h b/include/conio.h index 54667a3ca..f8a880c77 100644 --- a/include/conio.h +++ b/include/conio.h @@ -77,6 +77,8 @@ # include #elif defined(__NES__) # include +#elif defined(__PCE__) +# include #endif diff --git a/libsrc/pce/pcengine.h b/include/pce.h similarity index 100% rename from libsrc/pce/pcengine.h rename to include/pce.h diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index d344814ad..60096c81d 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -3,21 +3,21 @@ ; ; clock_t clock (void); ; - - .include "pcengine.inc" - .export _clock - .importzp sreg + .include "pcengine.inc" + + .export _clock + .importzp sreg .proc _clock - ldy #0 ; Byte 3 is always zero - sty sreg+1 - sty sreg + ldy #0 ; Byte 3 is always zero + sty sreg+1 + sty sreg - ldx _tickcount+1 - lda _tickcount - rts + ldx _tickcount+1 + lda _tickcount + rts .endproc diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index d9c5a2ccb..43ca5d602 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -8,6 +8,7 @@ ; .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib .import push0, _main, zerobss .import initheap diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s new file mode 100644 index 000000000..cfb59efe2 --- /dev/null +++ b/libsrc/pce/gotoxy.s @@ -0,0 +1,19 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void gotoxy (unsigned char x, unsigned char y); +; + + .export _gotoxy + .import popa, plot + + .include "pcengine.inc" + +_gotoxy: + + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position + + diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c new file mode 100644 index 000000000..6a7bb2341 --- /dev/null +++ b/testcode/lib/conio.c @@ -0,0 +1,10 @@ + +#include + +void main(void) +{ + clrscr(); +// cprintf("hello world"); + cputs("hello world"); + for(;;); +} \ No newline at end of file From 21999b081fb3b5e58266c01838de584a01819ce5 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 12 Jul 2015 10:32:55 +0200 Subject: [PATCH 05/28] simple conio test works again --- cfg/pce.cfg | 25 +++++---- libsrc/pce/_scrsize.s | 16 +++--- libsrc/pce/crt0.s | 128 ++++++++++++++++++++++-------------------- libsrc/pce/vce.s | 5 +- libsrc/pce/vdc.s | 14 ++--- libsrc/pce/vga.inc | 2 + 6 files changed, 96 insertions(+), 94 deletions(-) diff --git a/cfg/pce.cfg b/cfg/pce.cfg index b08e63814..f848fd737 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,5 +1,5 @@ SYMBOLS { - __STACKSIZE__: type = weak, value = $0300; # 3 pages stack + __STACKSIZE__: type = weak, value = $0300; # 3 pages stack } MEMORY { @@ -18,7 +18,7 @@ MEMORY { # Hardware Vectors at End of 2nd 8K ROM ROMV: start = $fff6, size = $a, file = %O,fill = yes; - ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; +# ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; # standard 2k SRAM (-zeropage) @@ -43,8 +43,8 @@ SEGMENTS { STARTUP: load = ROM0, type = ro, define = yes; INIT: load = ROM0, type = ro, define = yes, optional = yes; - CODE: load = ROM, type = ro, define = yes; - RODATA: load = ROM, type = ro, define = yes; + CODE: load = ROM0, type = ro, define = yes; + RODATA: load = ROM0, type = ro, define = yes; DATA: load = ROM0, run= RAM, type = rw, define = yes; # BSS: load = RAM2, type = bss, define = yes; @@ -58,12 +58,13 @@ SEGMENTS { } FEATURES { - CONDES: segment = STARTUP, - type=constructor, - label=__CONSTRUCTOR_TABLE__, - count=__CONSTRUCTOR_COUNT__; - CONDES: segment = STARTUP, - type=destructor, - label=__DESTRUCTOR_TABLE__, - count=__DESTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type=constructor, + label=__CONSTRUCTOR_TABLE__, + count=__CONSTRUCTOR_COUNT__; + + CONDES: segment = STARTUP, + type=destructor, + label=__DESTRUCTOR_TABLE__, + count=__DESTRUCTOR_COUNT__; } diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/_scrsize.s index 17b23b709..6e2b84a41 100644 --- a/libsrc/pce/_scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -2,16 +2,14 @@ ; Screen size variables ; - - -.export _screensize + .export _screensize _screensize: - ldx xsize - ldy ysize - rts + ldx xsize + ldy ysize + rts .rodata - .export xsize, ysize + .export xsize, ysize -xsize: .byte 64 -ysize: .byte 28 +xsize: .byte 64 +ysize: .byte 28 diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 43ca5d602..c6c0dabb8 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -43,56 +43,60 @@ start: ; setup the CPU and System-IRQ - ; Initialize CPU + ; Initialize CPU - sei - nop - csh - nop - cld - nop + sei + nop + csh ; set high speed CPU mode + nop + cld + nop - ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) - txs - txa - tam #0 ; 0000-1FFF = Hardware page + ; Setup stack and memory mapping + ldx #$FF ; Stack top ($21FF) + txs - lda #$F8 - tam #1 ; 2000-3FFF = Work RAM + ; at startup all MPRs are set to 0, so init them + lda #$ff + tam #1 ; 0000-1FFF = Hardware page + lda #$F8 + tam #2 ; 2000-3FFF = Work RAM + ;lda #$F7 + ;tam #2 ; 4000-5FFF = Save RAM + ;lda #1 + ;tam #3 ; 6000-7FFF Page 2 + ;lda #2 + ;tam #4 ; 8000-9FFF Page 3 + ;lda #3 + ;tam #5 ; A000-BFFF Page 4 + ;lda #4 + ;tam #6 ; C000-DFFF Page 5 + ;lda #0 + ;tam #7 ; e000-fFFF hucard/syscard bank 0 - lda #$F7 - tam #2 ; 4000-5FFF = Save RAM + ; Clear work RAM (2000-3FFF) + stz <$00 + tii $2000, $2001, $1FFF - lda #1 - tam #3 ; 6000-7FFF Page 2 - lda #2 - tam #4 ; 8000-9FFF Page 3 - lda #3 - tam #5 ; A000-BFFF Page 4 - lda #4 - tam #6 ; C000-DFFF Page 5 + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer - ; Initialize hardware - stz TIMER_COUNT ; Timer off - lda #$07 - sta IRQ_MASK ; Interrupts off - stz IRQ_STATUS ; Acknowledge timer + ;; i dont know why the heck this one doesnt + ;; work when called from a constructor :/ + .import vdc_init + jsr vdc_init - ; Clear work RAM - stz <$00 - tii $2000, $2001, $1FFF - - ;; i dont know why the heck this one doesnt - ;; work when called from a constructor :/ - .import vdc_init - jsr vdc_init ;; jsr joy_init - ; Turn on background and VD interrupt/IRQ1 - lda #$05 - sta IRQ_MASK ; IRQ1=on - cli + ; Turn on background and VD interrupt/IRQ1 + + lda #$05 + sta IRQ_MASK ; IRQ1=on + + cli ; Clear the BSS data @@ -162,8 +166,10 @@ start: ; Call module constructors jsr initlib -; .import initconio -; jsr initconio + + .import initconio + jsr initconio + ; Pass an empty command line @@ -189,34 +195,34 @@ _exit: ; ------------------------------------------------------------------------ _irq1: - pha - phx - phy + pha + phx + phy - inc _tickcount - bne @s - inc _tickcount+1 + inc _tickcount + bne @s + inc _tickcount+1 @s: - ; Acknowlege interrupt - ldaio VDC_CTRL + ; Acknowlege interrupt + ldaio VDC_CTRL - ply - plx - pla - rti + ply + plx + pla + rti _irq2: - rti + rti _nmi: - rti + rti _timer: - stz IRQ_STATUS - rti + stz IRQ_STATUS + rti - .export initmainargs + .export initmainargs initmainargs: - rts + rts ; ------------------------------------------------------------------------ ; hardware vectors diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index a5c919970..1f96c062c 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,6 +1,7 @@ - .include "pcengine.inc" - .export vce_init + .include "pcengine.inc" + + .export vce_init vce_init: stz VCE_ADDR_LO ; diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index a203cb058..47efdff55 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,15 +1,12 @@ - .include "pcengine.inc" + .include "pcengine.inc" HIRES = 1 - .export vdc_init + .export vdc_init vdc_init: - ;;lda $0000 - ;;.byte $ad,0,0 - - ldaio VDC_CTRL + ldaio VDC_CTRL VREG $00, $0000 ; MAWR VREG $01, $0000 ; MARR @@ -39,8 +36,5 @@ vdc_init: .endif - ;;lda $0000 - ;;.byte $ad,0,0 - - ldaio VDC_CTRL + ldaio VDC_CTRL rts diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index 6cbdd010c..2f9408f9a 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -1,4 +1,6 @@ +; VGA charset for the PC-Engine conio implementation + .byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E From 891cb97b2f0c0e6816b63ab7cb167ec17e67603d Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 12 Jul 2015 14:27:24 +0200 Subject: [PATCH 06/28] more cleanup, joystick works again --- libsrc/pce/pcengine.inc => asminc/pce.inc | 51 ++-- cfg/pce.cfg | 70 ++---- include/pce.h | 155 +++++++----- libsrc/pce/call.s | 12 +- libsrc/pce/clock.s | 13 +- libsrc/pce/clrscr.s | 2 +- libsrc/pce/color.s | 80 +++---- libsrc/pce/condes.s | 6 - libsrc/pce/conio.s | 175 +++++++------- libsrc/pce/cputc.s | 126 ++++------ libsrc/pce/crt0.s | 10 +- libsrc/pce/ctype.s | 161 +++++++++++++ libsrc/pce/gotoxy.s | 17 +- libsrc/pce/joy/pce-stdjoy.s | 162 +++++++++++++ libsrc/pce/joy_stat_stddrv.s | 14 ++ libsrc/pce/joy_stddrv.s | 13 + libsrc/pce/joytokbd.s | 275 ---------------------- libsrc/pce/kplot.s | 47 ++-- libsrc/pce/libref.s | 8 + libsrc/pce/pce-stdjoy.s | 191 --------------- libsrc/pce/psg.s | 44 ++-- libsrc/pce/readme.txt | 31 +++ libsrc/pce/revers.s | 6 +- libsrc/pce/vce.s | 2 +- libsrc/pce/vdc.s | 2 +- testcode/lib/conio.c | 10 - testcode/lib/pce/conio.c | 58 +++++ 27 files changed, 822 insertions(+), 919 deletions(-) rename libsrc/pce/pcengine.inc => asminc/pce.inc (74%) create mode 100644 libsrc/pce/ctype.s create mode 100644 libsrc/pce/joy/pce-stdjoy.s create mode 100644 libsrc/pce/joy_stat_stddrv.s create mode 100644 libsrc/pce/joy_stddrv.s delete mode 100644 libsrc/pce/joytokbd.s create mode 100644 libsrc/pce/libref.s delete mode 100644 libsrc/pce/pce-stdjoy.s create mode 100644 libsrc/pce/readme.txt delete mode 100644 testcode/lib/conio.c create mode 100644 testcode/lib/pce/conio.c diff --git a/libsrc/pce/pcengine.inc b/asminc/pce.inc similarity index 74% rename from libsrc/pce/pcengine.inc rename to asminc/pce.inc index a0ef03f6a..40e356cae 100644 --- a/libsrc/pce/pcengine.inc +++ b/asminc/pce.inc @@ -1,12 +1,17 @@ +; +; PCE definitions. By Groepaz/Hitmem. +; -; Write VDC register - .macro VREG arg1,arg2 - st0 #arg1 - st1 #<(arg2) - st2 #>(arg2) - .endmacro +;; FIXME: optimize zeropage usage -_tickcount= $20 +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 ;2 +CRAM_PTR = $34 ;2 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR = $38 +_tickcount = $39 ;2 screenrows = (224/8) charsperline = (512/8) @@ -15,14 +20,6 @@ xsize = charsperline CH_HLINE = 7 CH_VLINE = 7 -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 -CRAM_PTR = $34 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR=$38 - ; huc6270 - Video Display Controller (vdc) VDC_MAWR = 0 ; Memory Address Write Register @@ -45,9 +42,9 @@ VDC_DESR =16 ; (DMA) Destination Register VDC_LENR =17 ; (DMA) Length Register VDC_SATB =18 ; Sprite Attribute Table -VDC_CTRL = $0000 -VDC_DATA_LO = $0002 -VDC_DATA_HI = $0003 +VDC_CTRL = $0000 +VDC_DATA_LO = $0002 +VDC_DATA_HI = $0003 ; huc6260 - Video Color Encoder (vce) @@ -61,18 +58,17 @@ VCE_ADDR_HI = $0403 ; MSB of byte offset into palette VCE_DATA_LO = $0404 ; LSB of 16-bit palette data VCE_DATA_HI = $0405 ; MSB of 16-bit palette data -TIMER_COUNT = $0c00 -TIMER_CTRL = $0c01 +TIMER_COUNT = $0c00 +TIMER_CTRL = $0c01 -JOY_CTRL = $1000 +JOY_CTRL = $1000 -IRQ_MASK = $1402 -IRQ_STATUS = $1403 +IRQ_MASK = $1402 +IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 CDR_MEM_ENABLE = $1807 - ;; lda abs .macro ldaio arg1 .byte $ad @@ -88,3 +84,10 @@ CDR_MEM_ENABLE = $1807 .byte $9c .word arg1 .endmacro + +; Write VDC register +.macro VREG arg1,arg2 + st0 #arg1 + st1 #<(arg2) + st2 #>(arg2) +.endmacro diff --git a/cfg/pce.cfg b/cfg/pce.cfg index f848fd737..566554b2e 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,62 +1,32 @@ +# linker config to produce simple NEC PC-Engine cartridge (.pce) + SYMBOLS { __STACKSIZE__: type = weak, value = $0300; # 3 pages stack } + MEMORY { + # FIXME: is this correct? the first 3? bytes cant be used? + ZP: start = $03, size = $1A, type = rw, define = yes; - ZP: start = $00, size = $1A, type = rw, define = yes; - - # INES Cartridge Header - #HEADER: start = $0, size = $10, file = %O ,fill = yes; - - # 2 16K ROM Banks - # - startup - # - code - # - rodata - # - data (load) - # 1 8k CHR Bank - ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; - # Hardware Vectors at End of 2nd 8K ROM - ROMV: start = $fff6, size = $a, file = %O,fill = yes; - -# ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; - - - # standard 2k SRAM (-zeropage) - # $0100-$0200 cpu stack - # $0200-$0500 3 pages for ppu memory write buffer - # $0500-$0800 3 pages for cc65 parameter stack - #SRAM: start = $0500, size = $0300, define = yes; - - # additional 8K SRAM Bank - # - data (run) - # - bss - # - heap -# RAM: start = $2200, size = $1000, define = yes; -# RAM2: start = $3200, size = $0e00, define = yes; - RAM: start = $2200, size = $1e00, define = yes; + # reset-bank and hardware vectors + ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; + ROMV: start = $fff6, size = $a, file = %O,fill = yes; + # first RAM page (also contains stack and zeropage) + RAM: start = $2200, size = $1e00, define = yes; } + SEGMENTS { - #HEADER: load = HEADER, type = wprot; - - #aSTARTUP: load = ROM0, type = wprot, define = yes; - STARTUP: load = ROM0, type = ro, define = yes; - - INIT: load = ROM0, type = ro, define = yes, optional = yes; - CODE: load = ROM0, type = ro, define = yes; - RODATA: load = ROM0, type = ro, define = yes; - - DATA: load = ROM0, run= RAM, type = rw, define = yes; -# BSS: load = RAM2, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - - VECTORS: load = ROMV, type = rw, define = yes; - #CHARS: load = ROM2, type = rw; - - - ZEROPAGE: load = ZP, type = zp, define = yes; - + STARTUP: load = ROM0, type = ro, define = yes; + INIT: load = ROM0, type = ro, define = yes, optional = yes; + CODE: load = ROM0, type = ro, define = yes; + RODATA: load = ROM0, type = ro, define = yes; + DATA: load = ROM0, run= RAM, type = rw, define = yes; + BSS: load = RAM, type = bss, define = yes; + VECTORS: load = ROMV, type = rw, define = yes; + ZEROPAGE: load = ZP, type = zp, define = yes; } + FEATURES { CONDES: segment = STARTUP, type=constructor, diff --git a/include/pce.h b/include/pce.h index 8135679a2..70d5800d0 100644 --- a/include/pce.h +++ b/include/pce.h @@ -1,74 +1,99 @@ -#define CH_CROSS 0x10 - -#define CH_RTEE 0x17 -#define CH_LTEE 0x0f - -#define CH_ULCORNER 0x10 -#define CH_URCORNER 0x10 -#define CH_LLCORNER 0x10 -#define CH_LRCORNER 0x10 +/*****************************************************************************/ +/* */ +/* pce.h */ +/* */ +/* PC-Engine system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2015 Groepaz/Hitmen */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed 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. */ +/* */ +/*****************************************************************************/ -#define TV_NTSC 0 -#define TV_PAL 1 -#define get_tv() 0 -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? +#ifndef _PCE_H +#define _PCE_H -//#ifndef CH_ENTER -#define CH_ENTER '\n' -//#endif -#define CH_STOP 0x08 -#define CH_F1 0x14 -#define CH_F3 0x15 -#define CH_F5 0x16 -#define CH_F7 0x17 - -#define CH_CURS_UP 0x01 -#define CH_CURS_DOWN 0x02 - -#ifndef CH_CURS_LEFT -#define CH_CURS_LEFT 0x03 +/* Check for errors */ +#if !defined(__PCE__) +# error This module may only be used when compiling for the PCE! #endif -#ifndef CH_CURS_RIGHT -#define CH_CURS_RIGHT 0x04 +/* FIXME: the respective characters are not present in the VGA charset (yet) */ +#define CH_CROSS 0x10 + +#define CH_RTEE 0x17 +#define CH_LTEE 0x0f + +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x10 +#define CH_LLCORNER 0x10 +#define CH_LRCORNER 0x10 + +/* Color defines (CBM compatible, for conio) */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +#define CLOCKS_PER_SEC 50 // ??? +#define CLK_TCK 50 // ?!? + +#define TV_NTSC 0 +#define TV_PAL 1 +#define TV_OTHER 2 + +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + +/* The addresses of the static drivers */ +extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ + +#define JOY_FIRE_B 5 +#define JOY_START 6 +#define JOY_SELECT 7 + +/* FIXME: not implemented */ +void waitvblank (void); +/* Wait for the vertical blanking */ + +/* FIXME: not implemented */ +unsigned char get_tv (void); +/* Return the video mode the machine is using. */ + + +/* End of pce.h */ #endif - -#define CH_ESC 8 - -#define CH_DEL 20 - -/* Color defines */ -#define COLOR_BLACK 0x00 -#define COLOR_WHITE 0x01 -#define COLOR_RED 0x02 -#define COLOR_CYAN 0x03 -#define COLOR_VIOLET 0x04 -#define COLOR_GREEN 0x05 -#define COLOR_BLUE 0x06 -#define COLOR_YELLOW 0x07 -#define COLOR_ORANGE 0x08 -#define COLOR_BROWN 0x09 -#define COLOR_LIGHTRED 0x0A -#define COLOR_GRAY1 0x0B -#define COLOR_GRAY2 0x0C -#define COLOR_LIGHTGREEN 0x0D -#define COLOR_LIGHTBLUE 0x0E -#define COLOR_GRAY3 0x0F - -#define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 - -/* -void __fastcall__ waitvblank(void); - -unsigned char __fastcall__ cpeekcharxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekchar(void); -unsigned char __fastcall__ cpeekcolxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekcol(void); -*/ diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s index 34fbac08b..db120a72f 100644 --- a/libsrc/pce/call.s +++ b/libsrc/pce/call.s @@ -1,19 +1,17 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; CC65 runtime: call function via pointer in ax ; - .export callax + .export callax .code callax: - sta vec - stx vec+1 - jmp (vec) ; jump there + sta vec + stx vec+1 + jmp (vec) ; jump there .bss vec: - .res 2 \ No newline at end of file + .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 60096c81d..5f360916c 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -1,17 +1,15 @@ ; -; Ullrich von Bassewitz, 21.09.1998 -; ; clock_t clock (void); ; - .include "pcengine.inc" + .include "pce.inc" - .export _clock + .export _clock .importzp sreg - -.proc _clock - ldy #0 ; Byte 3 is always zero +.proc _clock + + ldy #0 ; Byte 3 is always zero sty sreg+1 sty sreg @@ -20,4 +18,3 @@ rts .endproc - diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 0a2b8b62d..93628ddd8 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export _clrscr _clrscr: diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 8d80114fc..0ec35f5b3 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -1,59 +1,57 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color); ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor, _bordercolor - .include "pcengine.inc" + .include "pce.inc" _textcolor: - ldx CHARCOLOR ; get old value - sta CHARCOLOR ; set new value - txa - rts + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts _bgcolor: - ldx BGCOLOR ; get old value - sta BGCOLOR ; set new value - asl a - tay + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay - stz VCE_ADDR_LO - stz VCE_ADDR_HI - lda colors,y - sta VCE_DATA_LO - lda colors+1,y - sta VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI - txa - rts + txa + rts _bordercolor: - lda #0 - txa - rts + lda #0 + txa + rts - .export colors + .export colors -colors: ; G R B - .word ((0<<6)+(0<<3)+(0)) ; 0 black - .word ((7<<6)+(7<<3)+(7)) ; 1 white - .word ((0<<6)+(7<<3)+(0)) ; 2 red - .word ((7<<6)+(0<<3)+(7)) ; 3 cyan - .word ((0<<6)+(5<<3)+(7)) ; 4 violett - .word ((7<<6)+(0<<3)+(0)) ; 5 green - .word ((0<<6)+(0<<3)+(7)) ; 6 blue - .word ((7<<6)+(7<<3)+(0)) ; 7 yellow - .word ((5<<6)+(7<<3)+(0)) ; 8 orange - .word ((3<<6)+(4<<3)+(3)) ; 9 brown - .word ((4<<6)+(7<<3)+(4)) ; a light red - .word ((3<<6)+(3<<3)+(3)) ; b dark grey - .word ((4<<6)+(4<<3)+(4)) ; c middle grey - .word ((7<<6)+(4<<3)+(4)) ; d light green - .word ((4<<6)+(4<<3)+(7)) ; e light blue - .word ((6<<6)+(6<<3)+(6)) ; f light gray +colors: ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s index dd7bd30b3..aa28833c2 100644 --- a/libsrc/pce/condes.s +++ b/libsrc/pce/condes.s @@ -94,9 +94,3 @@ getbyt: ;;getbyt_: lda $FFFF,y rts - -;; callax doesnt work? why?! -;_callax: -; sta @l+1 -; stx @l+2 -;@l: jmp $dead diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 0a66cf454..60801e172 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,122 +1,105 @@ - .include "pcengine.inc" - .import vce_init - .import psg_init - .import vdc_init + .include "pce.inc" - .export initconio - .export _conio_init + .import vce_init + .import psg_init + .import vdc_init - .constructor initconio, 24 + .export initconio + .export _conio_init - .macpack longbranch + .constructor initconio, 24 + + .macpack longbranch initconio: - ;; jsr vdc_init - jsr vce_init - jsr psg_init - jsr conio_init - jsr set_palette +;; jsr vdc_init + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette - st0 #VDC_RCR - st1 #<$0088 - st2 #>$0088 - rts + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts - .import colors + .import colors set_palette: + stz VCE_ADDR_LO + stz VCE_ADDR_HI - ; Make palette (use VGA palette?) - ; stz VCE_ADDR_LO - ; stz VCE_ADDR_HI - ; clx - ; cly - vce_loop: ;; stx VCE_DATA_LO - ;; sty VCE_DATA_HI - ; inx - ; cpx #$00 - ; bne vce_loop - ; iny - ; cpy #$02 - ; bne vce_loop - - - stz VCE_ADDR_LO - stz VCE_ADDR_HI - - ldx #0 + ldx #0 @lp: - .repeat 16 - lda colors,x - sta VCE_DATA_LO - lda colors+1,x - sta VCE_DATA_HI - .endrepeat + .repeat 16 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + .endrepeat - inx - inx - cpx #16*2;*5 - jne @lp + inx + inx + cpx #16*2 + jne @lp - stz VCE_ADDR_LO - stz VCE_ADDR_HI - stz VCE_DATA_LO - stz VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI -; so it will get linked in + ; so it will get linked in _conio_init: - rts + rts ;---------------------------------------------------------------------------- ; ;---------------------------------------------------------------------------- - .importzp ptr1 - + .importzp ptr1 conio_init: + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 - ; Load font - st0 #VDC_MAWR - st1 #<$2000 - st2 #>$2000 + ; ptr to font data + lda #font + sta ptr1+1 - ; ptr to font data - lda #font - sta ptr1+1 + st0 #VDC_VWR ; VWR + ldy #$80 ; 128 chars +charloop: ldx #$08 ; 8 bytes/char +lineloop: + lda (ptr1) + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 - st0 #VDC_VWR ; VWR - ldy #$80 ; 128 chars - charloop: ldx #$08 ; 8 bytes/char - lineloop: - ;;lda [$00] ; read font byte - lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 +fillloop: st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character - clc ; increment font pointer - lda ptr1 - adc #$01 - sta ptr1 - lda ptr1+1 - adc #$00 - sta ptr1+1 - dex - bne lineloop ; next bitplane 0 byte - ldx #$08 ; fill bitplane 2/3 with 0 - fillloop: st1 #$00 - st2 #$00 - dex - bne fillloop ; next byte - dey - bne charloop ; next character - - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR - rts + rts - .rodata -font: .include "vga.inc" + .rodata +font: + .include "vga.inc" diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index 8a02a3499..ec63b7565 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -1,81 +1,59 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - .import PLOT - - .importzp tmp3,tmp4 - - .include "pcengine.inc" + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + .importzp tmp3,tmp4 + .include "pce.inc" _cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C ; Plot a character - also used as internal function -_cputc: cmp #$0d ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers -L1: cmp #$0a ; LF? - beq newline ; Recalculate pointers +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: - jsr putchar ; Write the character to the screen + jsr putchar ; Write the character to the screen ; Advance cursor position advance: - ldy CURS_X - iny - cpy #xsize - bne L3 - jsr newline ; new line - ldy #0 ; + cr -L3: sty CURS_X - jmp plot - ;rts + ldy CURS_X + iny + cpy #xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot newline: -; lda #xsize -; clc -; adc SCREEN_PTR -; sta SCREEN_PTR -; bcc L4 -; inc SCREEN_PTR+1 -;; clc -;L4:; lda #xsize - ; adc CRAM_PTR - ; sta CRAM_PTR - ; bcc L5 - ; inc CRAM_PTR+1 -;L5: - - inc CURS_Y - -; jmp plot -; rts + inc CURS_Y ; Set cursor position, calculate RAM pointers -plot: ldy CURS_X - ldx CURS_Y - clc - jmp PLOT ; Set the new cursor +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor @@ -84,34 +62,32 @@ plot: ldy CURS_X putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit - tax + tax - st0 #VDC_MAWR ; Memory Adress Write + st0 #VDC_MAWR ; Memory Adress Write - lda SCREEN_PTR - staio VDC_DATA_LO + lda SCREEN_PTR + staio VDC_DATA_LO - lda SCREEN_PTR+1 - staio VDC_DATA_HI + lda SCREEN_PTR+1 + staio VDC_DATA_HI - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - txa - staio VDC_DATA_LO ; character + txa + staio VDC_DATA_LO ; character - ;;st2 #$32 ; attrib ?! - lda CHARCOLOR - - ;;lda #2 - asl a - asl a - asl a - asl a + lda CHARCOLOR - and #$f0 - ora #$02 - staio VDC_DATA_HI + asl a + asl a + asl a + asl a - rts + and #$f0 + ora #$02 + staio VDC_DATA_HI + + rts diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index c6c0dabb8..06454998b 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -24,7 +24,7 @@ .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated .import __BSS_SIZE__ - .include "pcengine.inc" + .include "pce.inc" .importzp sp .importzp ptr1,ptr2 @@ -84,10 +84,9 @@ start: sta IRQ_MASK ; Interrupts off stz IRQ_STATUS ; Acknowledge timer - ;; i dont know why the heck this one doesnt - ;; work when called from a constructor :/ - .import vdc_init - jsr vdc_init + ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ + .import vdc_init + jsr vdc_init ;; jsr joy_init @@ -167,6 +166,7 @@ start: jsr initlib + ;; FIXME: this should be called from a constructor instead .import initconio jsr initconio diff --git a/libsrc/pce/ctype.s b/libsrc/pce/ctype.s new file mode 100644 index 000000000..fa9a65c8b --- /dev/null +++ b/libsrc/pce/ctype.s @@ -0,0 +1,161 @@ +; +; Stefan Haubenthal with minor changes from Ullrich von Bassewitz, 2003-05-02 +; +; Character specification table. +; + + .include "ctype.inc" + +; The tables are readonly, put them into the rodata segment + +.rodata + +; The following 256 byte wide table specifies attributes for the isxxx type +; of functions. Doing it by a table means some overhead in space, but it +; has major advantages: +; +; * It is fast. If it were'nt for the slow parameter passing of cc65, one +; could even define macros for the isxxx functions (this is usually +; done on other platforms). +; +; * It is highly portable. The only unportable part is the table itself, +; all real code goes into the common library. +; +; * We save some code in the isxxx functions. + + +__ctype: + .repeat 2 + .byte CT_CTRL ; 0/00 ___ctrl_@___ + .byte CT_CTRL ; 1/01 ___ctrl_A___ + .byte CT_CTRL ; 2/02 ___ctrl_B___ + .byte CT_CTRL ; 3/03 ___ctrl_C___ + .byte CT_CTRL ; 4/04 ___ctrl_D___ + .byte CT_CTRL ; 5/05 ___ctrl_E___ + .byte CT_CTRL ; 6/06 ___ctrl_F___ + .byte CT_CTRL ; 7/07 ___ctrl_G___ + .byte CT_CTRL ; 8/08 ___ctrl_H___ + .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB + ; 9/09 ___ctrl_I___ + .byte CT_CTRL | CT_OTHER_WS ; 10/0a ___ctrl_J___ + .byte CT_CTRL | CT_OTHER_WS ; 11/0b ___ctrl_K___ + .byte CT_CTRL | CT_OTHER_WS ; 12/0c ___ctrl_L___ + .byte CT_CTRL | CT_OTHER_WS ; 13/0d ___ctrl_M___ + .byte CT_CTRL ; 14/0e ___ctrl_N___ + .byte CT_CTRL ; 15/0f ___ctrl_O___ + .byte CT_CTRL ; 16/10 ___ctrl_P___ + .byte CT_CTRL ; 17/11 ___ctrl_Q___ + .byte CT_CTRL ; 18/12 ___ctrl_R___ + .byte CT_CTRL ; 19/13 ___ctrl_S___ + .byte CT_CTRL ; 20/14 ___ctrl_T___ + .byte CT_CTRL ; 21/15 ___ctrl_U___ + .byte CT_CTRL ; 22/16 ___ctrl_V___ + .byte CT_CTRL ; 23/17 ___ctrl_W___ + .byte CT_CTRL ; 24/18 ___ctrl_X___ + .byte CT_CTRL ; 25/19 ___ctrl_Y___ + .byte CT_CTRL ; 26/1a ___ctrl_Z___ + .byte CT_CTRL ; 27/1b ___ctrl_[___ + .byte CT_CTRL ; 28/1c ___ctrl_\___ + .byte CT_CTRL ; 29/1d ___ctrl_]___ + .byte CT_CTRL ; 30/1e ___ctrl_^___ + .byte CT_CTRL ; 31/1f ___ctrl_____ + .byte CT_SPACE | CT_SPACE_TAB ; 32/20 ___SPACE___ + .byte CT_NONE ; 33/21 _____!_____ + .byte CT_NONE ; 34/22 _____"_____ + .byte CT_NONE ; 35/23 _____#_____ + .byte CT_NONE ; 36/24 _____$_____ + .byte CT_NONE ; 37/25 _____%_____ + .byte CT_NONE ; 38/26 _____&_____ + .byte CT_NONE ; 39/27 _____'_____ + .byte CT_NONE ; 40/28 _____(_____ + .byte CT_NONE ; 41/29 _____)_____ + .byte CT_NONE ; 42/2a _____*_____ + .byte CT_NONE ; 43/2b _____+_____ + .byte CT_NONE ; 44/2c _____,_____ + .byte CT_NONE ; 45/2d _____-_____ + .byte CT_NONE ; 46/2e _____._____ + .byte CT_NONE ; 47/2f _____/_____ + .byte CT_DIGIT | CT_XDIGIT ; 48/30 _____0_____ + .byte CT_DIGIT | CT_XDIGIT ; 49/31 _____1_____ + .byte CT_DIGIT | CT_XDIGIT ; 50/32 _____2_____ + .byte CT_DIGIT | CT_XDIGIT ; 51/33 _____3_____ + .byte CT_DIGIT | CT_XDIGIT ; 52/34 _____4_____ + .byte CT_DIGIT | CT_XDIGIT ; 53/35 _____5_____ + .byte CT_DIGIT | CT_XDIGIT ; 54/36 _____6_____ + .byte CT_DIGIT | CT_XDIGIT ; 55/37 _____7_____ + .byte CT_DIGIT | CT_XDIGIT ; 56/38 _____8_____ + .byte CT_DIGIT | CT_XDIGIT ; 57/39 _____9_____ + .byte CT_NONE ; 58/3a _____:_____ + .byte CT_NONE ; 59/3b _____;_____ + .byte CT_NONE ; 60/3c _____<_____ + .byte CT_NONE ; 61/3d _____=_____ + .byte CT_NONE ; 62/3e _____>_____ + .byte CT_NONE ; 63/3f _____?_____ + + .byte CT_NONE ; 64/40 _____@_____ + .byte CT_UPPER | CT_XDIGIT ; 65/41 _____A_____ + .byte CT_UPPER | CT_XDIGIT ; 66/42 _____B_____ + .byte CT_UPPER | CT_XDIGIT ; 67/43 _____C_____ + .byte CT_UPPER | CT_XDIGIT ; 68/44 _____D_____ + .byte CT_UPPER | CT_XDIGIT ; 69/45 _____E_____ + .byte CT_UPPER | CT_XDIGIT ; 70/46 _____F_____ + .byte CT_UPPER ; 71/47 _____G_____ + .byte CT_UPPER ; 72/48 _____H_____ + .byte CT_UPPER ; 73/49 _____I_____ + .byte CT_UPPER ; 74/4a _____J_____ + .byte CT_UPPER ; 75/4b _____K_____ + .byte CT_UPPER ; 76/4c _____L_____ + .byte CT_UPPER ; 77/4d _____M_____ + .byte CT_UPPER ; 78/4e _____N_____ + .byte CT_UPPER ; 79/4f _____O_____ + .byte CT_UPPER ; 80/50 _____P_____ + .byte CT_UPPER ; 81/51 _____Q_____ + .byte CT_UPPER ; 82/52 _____R_____ + .byte CT_UPPER ; 83/53 _____S_____ + .byte CT_UPPER ; 84/54 _____T_____ + .byte CT_UPPER ; 85/55 _____U_____ + .byte CT_UPPER ; 86/56 _____V_____ + .byte CT_UPPER ; 87/57 _____W_____ + .byte CT_UPPER ; 88/58 _____X_____ + .byte CT_UPPER ; 89/59 _____Y_____ + .byte CT_UPPER ; 90/5a _____Z_____ + .byte CT_NONE ; 91/5b _____[_____ + .byte CT_NONE ; 92/5c _____\_____ + .byte CT_NONE ; 93/5d _____]_____ + .byte CT_NONE ; 94/5e _____^_____ + .byte CT_NONE ; 95/5f _UNDERLINE_ + .byte CT_NONE ; 96/60 ___grave___ + .byte CT_LOWER | CT_XDIGIT ; 97/61 _____a_____ + .byte CT_LOWER | CT_XDIGIT ; 98/62 _____b_____ + .byte CT_LOWER | CT_XDIGIT ; 99/63 _____c_____ + .byte CT_LOWER | CT_XDIGIT ; 100/64 _____d_____ + .byte CT_LOWER | CT_XDIGIT ; 101/65 _____e_____ + .byte CT_LOWER | CT_XDIGIT ; 102/66 _____f_____ + .byte CT_LOWER ; 103/67 _____g_____ + .byte CT_LOWER ; 104/68 _____h_____ + .byte CT_LOWER ; 105/69 _____i_____ + .byte CT_LOWER ; 106/6a _____j_____ + .byte CT_LOWER ; 107/6b _____k_____ + .byte CT_LOWER ; 108/6c _____l_____ + .byte CT_LOWER ; 109/6d _____m_____ + .byte CT_LOWER ; 110/6e _____n_____ + .byte CT_LOWER ; 111/6f _____o_____ + .byte CT_LOWER ; 112/70 _____p_____ + .byte CT_LOWER ; 113/71 _____q_____ + .byte CT_LOWER ; 114/72 _____r_____ + .byte CT_LOWER ; 115/73 _____s_____ + .byte CT_LOWER ; 116/74 _____t_____ + .byte CT_LOWER ; 117/75 _____u_____ + .byte CT_LOWER ; 118/76 _____v_____ + .byte CT_LOWER ; 119/77 _____w_____ + .byte CT_LOWER ; 120/78 _____x_____ + .byte CT_LOWER ; 121/79 _____y_____ + .byte CT_LOWER ; 122/7a _____z_____ + .byte CT_NONE ; 123/7b _____{_____ + .byte CT_NONE ; 124/7c _____|_____ + .byte CT_NONE ; 125/7d _____}_____ + .byte CT_NONE ; 126/7e _____~_____ + .byte CT_OTHER_WS ; 127/7f ____DEL____ + .endrepeat + + diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index cfb59efe2..24f917cd6 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -1,19 +1,16 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - .import popa, plot + .export _gotoxy + .import popa, plot - .include "pcengine.inc" + .include "pce.inc" _gotoxy: - - sta CURS_Y ; Set Y - jsr popa ; Get X - sta CURS_X ; Set X - jmp plot ; Set the cursor position + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s new file mode 100644 index 000000000..6bc6bdf57 --- /dev/null +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -0,0 +1,162 @@ + +; +; Standard joystick driver for the PCEngine +; + + .include "joy-kernel.inc" + .include "joy-error.inc" + + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _pce_stdjoy_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; Button state masks (8 values) + +;extern const unsigned char joy_masks[8]; + + .export _joy_masks + +_joy_masks: + .byte $10 ; JOY_UP + .byte $40 ; JOY_DOWN + .byte $80 ; JOY_LEFT + .byte $20 ; JOY_RIGHT + .byte $02 ; JOY_FIRE A ; FIXME: is this correct? + .byte $01 ; JOY_FIRE B ; FIXME: is this correct? + .byte $04 ; JOY_START ; FIXME: is this correct? + .byte $08 ; JOY_SELECT ; FIXME: is this correct? + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READJOY + .addr 0 ; IRQ entry unused + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 4 ; Number of joysticks we support + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #JOY_ERR_OK + +; rts ; Run into DEINSTALL instead + +; ------------------------------------------------------------------------ +; DEINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; +;unsigned char __fastcall__ joy_count (void); + +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +;unsigned char __fastcall__ joy_read (unsigned char joystick); + +READJOY: + pha + jsr read_joy + pla + tax ; Joystick number into X + + ; return value from buffer + +joy1: + lda padbuffer,x + ldx #0 + rts + +read_joy: + ; reset multitap counter + lda #$01 + sta $1000 + pha + pla + nop + nop + + lda #$03 + sta $1000 + pha + pla + nop + nop + + cly +nextpad: + lda #$01 + sta $1000 ; sel = 1 + pha + pla + nop + nop + + lda $1000 + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value + + stz $1000 + pha + pla + nop + nop + + lda $1000 + and #$0F + ora padbuffer, y ; second half of new value + + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts + +.bss + +padbuffer: + .res 4 + diff --git a/libsrc/pce/joy_stat_stddrv.s b/libsrc/pce/joy_stat_stddrv.s new file mode 100644 index 000000000..3972569ed --- /dev/null +++ b/libsrc/pce/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _pce_stdjoy_joy + +.rodata + +_joy_static_stddrv := _pce_stdjoy_joy diff --git a/libsrc/pce/joy_stddrv.s b/libsrc/pce/joy_stddrv.s new file mode 100644 index 000000000..e0ed6957e --- /dev/null +++ b/libsrc/pce/joy_stddrv.s @@ -0,0 +1,13 @@ +; +; Name of the standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "pce-stdjoy.joy" diff --git a/libsrc/pce/joytokbd.s b/libsrc/pce/joytokbd.s deleted file mode 100644 index 1e8258e08..000000000 --- a/libsrc/pce/joytokbd.s +++ /dev/null @@ -1,275 +0,0 @@ -; -; File generated by cc65 v 2.9.5 -; - .fopt compiler,"cc65 v 2.9.5" - .autoimport on - .case on - .debuginfo off - .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 - .macpack longbranch - .import _joy_masks - .import _joy_read - .import _clock - .export _kbhit - .export _cgetc - -.segment "DATA" - -__lastkey: - .byte $00 -__chardelay: - .dword $00000000 -_rptkey: - .byte $00 - -; --------------------------------------------------------------- -; void _getkey (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc __getkey - -.segment "CODE" - - jsr decsp2 - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L003F - lda #$00 - jsr _joy_read - ldy #$01 - sta (sp),y - ldx #$00 - lda #$00 - ldy #$00 - sta (sp),y - ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+4 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0010 - ldx #$00 - lda #$0A - ldy #$00 - sta (sp),y - jmp L003A -L0010: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0016 - ldx #$00 - lda #$01 - ldy #$00 - sta (sp),y - jmp L003A -L0016: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+2 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L001C - ldx #$00 - lda #$03 - ldy #$00 - sta (sp),y - jmp L003A -L001C: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+3 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0022 - ldx #$00 - lda #$04 - ldy #$00 - sta (sp),y - jmp L003A -L0022: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+1 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0028 - ldx #$00 - lda #$02 - ldy #$00 - sta (sp),y - jmp L003A -L0028: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+7 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L002E - ldx #$00 - lda #$14 - ldy #$00 - sta (sp),y - jmp L003A -L002E: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+5 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0034 - ldx #$00 - lda #$15 - ldy #$00 - sta (sp),y - jmp L003A -L0034: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+6 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L003A - ldx #$00 - lda #$16 - ldy #$00 - sta (sp),y -L003A: ldy #$00 - ldx #$00 - lda (sp),y - cmp #$00 - jsr boolne - jeq L003F - ldy #$00 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _rptkey - jsr toseqax - jeq L0043 - lda __chardelay+3 - sta sreg+1 - lda __chardelay+2 - sta sreg - ldx __chardelay+1 - lda __chardelay - jsr pusheax - jsr _clock - jsr tosugteax - jeq L0043 - jmp L003F -L0043: ldy #$00 - ldx #$00 - lda (sp),y - sta _rptkey - jsr _clock - ldy #$06 - jsr inceaxy - sta __chardelay - stx __chardelay+1 - ldy sreg - sty __chardelay+2 - ldy sreg+1 - sty __chardelay+3 - ldy #$00 - ldx #$00 - lda (sp),y - sta __lastkey -L003F: jsr incsp2 - rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ kbhit (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _kbhit - -.segment "CODE" - - jsr __getkey - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L004E - ldx #$00 - lda #$00 - jmp L0052 - jmp L0052 -L004E: ldx #$00 - lda #$01 - jmp L0052 -L0052: rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ cgetc (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _cgetc - -.segment "CODE" - - jsr decsp1 -L0056: ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L0057 - jsr __getkey - jmp L0056 -L0057: ldx #$00 - lda __lastkey - ldy #$00 - sta (sp),y - ldx #$00 - lda #$00 - sta __lastkey - ldy #$00 - ldx #$00 - lda (sp),y - jmp L0055 -L0055: jsr incsp1 - rts - -.endproc - diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index f050d78ef..beb151a7b 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -1,41 +1,32 @@ - .export PLOT + .export PLOT - .include "pcengine.inc" + .include "pce.inc" PLOT: + bcs @getpos - bcs @getpos - - tya - clc - adc _plotlo,x - sta SCREEN_PTR - - lda _plothi,x - adc #0 - sta SCREEN_PTR+1 - - ;clc - ;adc _colplot,x - ;sta CRAM_PTR - - ;lda #$23 - ;sta CRAM_PTR+1 + tya + clc + adc _plotlo,x + sta SCREEN_PTR + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 @getpos: - ldx CURS_Y - ldy CURS_X - rts + ldx CURS_Y + ldy CURS_X + rts _plotlo: - .repeat screenrows,line - .byte <($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat _plothi: - .repeat screenrows,line - .byte >($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat diff --git a/libsrc/pce/libref.s b/libsrc/pce/libref.s new file mode 100644 index 000000000..e4afa7eb1 --- /dev/null +++ b/libsrc/pce/libref.s @@ -0,0 +1,8 @@ +; +; Oliver Schmidt, 2013-05-31 +; + + .export joy_libref + .import _exit + +joy_libref := _exit diff --git a/libsrc/pce/pce-stdjoy.s b/libsrc/pce/pce-stdjoy.s deleted file mode 100644 index 60c77db1e..000000000 --- a/libsrc/pce/pce-stdjoy.s +++ /dev/null @@ -1,191 +0,0 @@ - -; -; Standard joystick driver for the PCEngine -; -; Ullrich von Bassewitz, 2002-12-20 -; - - ;;.include "zeropage.inc" - - ;;.include "joy-kernel.inc" - - ;;.include "joy-error.inc" - JOY_ERR_OK=0; - .include "pcengine.inc" - - .macpack generic - -; ------------------------------------------------------------------------ -; Header. Includes jump table - -.segment "CODE" - -; Driver signature - -;; .byte $6A, $6F, $79 ; "joy" -;; .byte $00 ; Driver API version number - -; Button state masks (8 values) - -;extern const unsigned char joy_masks[8]; - - .export _joy_masks - -_joy_masks: - .byte $10 ; JOY_UP - .byte $40 ; JOY_DOWN - .byte $80 ; JOY_LEFT - .byte $20 ; JOY_RIGHT - .byte $04 ; ? JOY_FIRE - .byte $02 ; ? Future expansion - .byte $01 ; ? Future expansion - .byte $08 ; ? Future expansion - -; Jump table. - -;; .word INSTALL -;; .word DEINSTALL -;; .word COUNT -;; .word READ - -; ------------------------------------------------------------------------ -; Constants - -JOY_COUNT = 4 ; Number of joysticks we support - - -; ------------------------------------------------------------------------ -; Data. - - -.code - - -;extern const char joy_stddrv[]; - - .export _joy_stddrv -_joy_stddrv: - .byte 0 - - - .export _joy_load_driver - .export _joy_unload - -;unsigned char __fastcall__ joy_unload (void); -;unsigned char __fastcall__ joy_load_driver (const char* driver); -_joy_load_driver: -_joy_unload: - -; ------------------------------------------------------------------------ -; INSTALL routine. Is called after the driver is loaded into memory. If -; possible, check if the hardware is present and determine the amount of -; memory available. -; Must return an JOY_ERR_xx code in a/x. -; - -INSTALL: - lda #JOY_ERR_OK - -; rts ; Run into DEINSTALL instead - -; ------------------------------------------------------------------------ -; DEINSTALL routine. Is called before the driver is removed from memory. -; Can do cleanup or whatever. Must not return anything. -; - -DEINSTALL: - rts - - -; ------------------------------------------------------------------------ -; COUNT: Return the total number of available joysticks in a/x. -; -;unsigned char __fastcall__ joy_count (void); - - .export _joy_count - -_joy_count: -COUNT: - lda #JOY_COUNT - rts - -; ------------------------------------------------------------------------ -; READ: Read a particular joystick passed in A. -; -;unsigned char __fastcall__ joy_read (unsigned char joystick); - - .export _joy_read - -_joy_read: -READ: - pha - jsr read_joy - pla - tax ; Joystick number into X - - ; return value from buffer - -joy1: - lda padbuffer,x - ldx #0 - rts - -.code - -read_joy: - ; reset multitap counter - lda #$01 - sta $1000 - pha - pla - nop - nop - - lda #$03 - sta $1000 - pha - pla - nop - nop - - cly -nextpad: - lda #$01 - sta $1000 ; sel = 1 - pha - pla - nop - nop - - lda $1000 - asl a - asl a - asl a - asl a - sta padbuffer, y ; store new value - - stz $1000 - pha - pla - nop - nop - - lda $1000 - and #$0F - ora padbuffer, y ; second half of new value - - eor #$FF - sta padbuffer, y ; store new value - - iny - cpy #$05 - bcc nextpad - rts - -.bss - -padbuffer: - .res 4 - diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index ebf35d952..431f58834 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,29 +1,29 @@ - - .include "pcengine.inc" - .export psg_init + .include "pce.inc" + + .export psg_init psg_init: - clx - stx $0800 ; Select channel + clx + stx $0800 ; Select channel psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control - cly + cly psg_clear_waveform: stz $0806 ; Clear waveform byte - iny - cpy #$20 - bne psg_clear_waveform + iny + cpy #$20 + bne psg_clear_waveform + + inx + cpx #$06 + bne psg_clear_loop + rts - inx - cpx #$06 - bne psg_clear_loop - rts - diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt new file mode 100644 index 000000000..e99b55122 --- /dev/null +++ b/libsrc/pce/readme.txt @@ -0,0 +1,31 @@ + +joystick support should get verified on real hw, the masks for buttons may be +wrong. + +clock() does not work for unknown reasons + +get_tv() is a dummy function and always returns 0 + +revers() is a dummy function, actual reverse output is not supported yet + +waitvblank() is missing + +some graphical petscii chars should get added to the charset + +conio-init should get initialized from a constructor rather than always get +called from crt0 + +-------------------------------------------------------------------------------- + +a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) + +run the compiled binary like this: + +> mednafen -force_module pce + +joypad keys are mapped like this: + +w/s/a/d up/down/left/right +numpad 2 (?) button +numpad 3 (?) button +enter (start) button diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index d1358a52b..c39a9f843 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,5 @@ - .export _revers + .export _revers _revers: - lda #0 - rts + lda #0 + rts diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 1f96c062c..461fd1e75 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export vce_init diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index 47efdff55..d1ead937e 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" HIRES = 1 diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c deleted file mode 100644 index 6a7bb2341..000000000 --- a/testcode/lib/conio.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include - -void main(void) -{ - clrscr(); -// cprintf("hello world"); - cputs("hello world"); - for(;;); -} \ No newline at end of file diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c new file mode 100644 index 000000000..306eb1ebb --- /dev/null +++ b/testcode/lib/pce/conio.c @@ -0,0 +1,58 @@ + +#include +#include +#include + +static int datavar = 10; + +void main(void) +{ + int stackvar = 42; + int i, j; + + joy_install(&joy_static_stddrv); + + clrscr(); + + cputs("hello world"); + cputsxy(0, 2, "colors:" ); + for (i = 0; i < 16; ++i) { + textcolor(i); + cputc('X'); + } + textcolor(1); + + gotoxy(0,4); + cprintf("datavar: %02x\n\r", datavar); + cprintf("stackvar: %02x\n\r", stackvar); + + j = joy_count(); + gotoxy(0,10); + cprintf("Found %d Joysticks.", j); + + for(;;) + { + gotoxy(13,4); + cprintf("%02x", datavar); + gotoxy(13,5); + cprintf("%02x", stackvar); + ++datavar; ++stackvar; + + gotoxy(0,8); + cprintf("clock: %08x", clock()); + for (i = 0; i < 4; ++i) + { + gotoxy(0, 12 + i); + j = joy_read (i); + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s", + i, j, + (j & joy_masks[JOY_UP])? " up " : " ---- ", + (j & joy_masks[JOY_DOWN])? " down " : " ---- ", + (j & joy_masks[JOY_LEFT])? " left " : " ---- ", + (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", + (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + } + } + for(;;); +} \ No newline at end of file From 9e1d39a409b02cba9277ec1231863a2c7f99b100 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 12 Jul 2015 16:40:52 +0200 Subject: [PATCH 07/28] more cleanup and fixing --- asminc/pce.inc | 4 +- cfg/pce.cfg | 23 +-- include/pce.h | 8 +- libsrc/pce/call.s | 17 --- libsrc/pce/clock.s | 8 +- libsrc/pce/condes.s | 96 ------------ libsrc/pce/conio.s | 3 - libsrc/pce/crt0.s | 215 ++++++++++++--------------- libsrc/pce/joy/pce-stdjoy.s | 5 - libsrc/pce/readme.txt | 31 +++- libsrc/pce/{_scrsize.s => scrsize.s} | 0 testcode/lib/pce/Makefile | 12 ++ testcode/lib/pce/conio.c | 5 +- 13 files changed, 159 insertions(+), 268 deletions(-) delete mode 100644 libsrc/pce/call.s delete mode 100644 libsrc/pce/condes.s rename libsrc/pce/{_scrsize.s => scrsize.s} (100%) create mode 100644 testcode/lib/pce/Makefile diff --git a/asminc/pce.inc b/asminc/pce.inc index 40e356cae..6d1541d64 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -11,7 +11,7 @@ CRAM_PTR = $34 ;2 CHARCOLOR = $36 RVS = $37 BGCOLOR = $38 -_tickcount = $39 ;2 +_tickcount = $39 ;4 screenrows = (224/8) charsperline = (512/8) @@ -74,11 +74,13 @@ CDR_MEM_ENABLE = $1807 .byte $ad .word arg1 .endmacro + ;; sta abs .macro staio arg1 .byte $8d .word arg1 .endmacro + ;; stz abs .macro stzio arg1 .byte $9c diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 566554b2e..adb420f32 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -28,13 +28,18 @@ SEGMENTS { } FEATURES { - CONDES: segment = STARTUP, - type=constructor, - label=__CONSTRUCTOR_TABLE__, - count=__CONSTRUCTOR_COUNT__; - - CONDES: segment = STARTUP, - type=destructor, - label=__DESTRUCTOR_TABLE__, - count=__DESTRUCTOR_COUNT__; + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; +# FIXME: interruptor support is missing +# CONDES: type = interruptor, +# label = __INTERRUPTOR_TABLE__, +# count = __INTERRUPTOR_COUNT__, +# segment = RODATA, +# import = __CALLIRQ__; } diff --git a/include/pce.h b/include/pce.h index 70d5800d0..912e0157b 100644 --- a/include/pce.h +++ b/include/pce.h @@ -28,13 +28,9 @@ /* */ /*****************************************************************************/ - - #ifndef _PCE_H #define _PCE_H - - /* Check for errors */ #if !defined(__PCE__) # error This module may only be used when compiling for the PCE! @@ -69,8 +65,8 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? +#define CLOCKS_PER_SEC 50 // FIXME: is this correct? +#define CLK_TCK 50 // FIXME: is this correct? #define TV_NTSC 0 #define TV_PAL 1 diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s deleted file mode 100644 index db120a72f..000000000 --- a/libsrc/pce/call.s +++ /dev/null @@ -1,17 +0,0 @@ -; -; CC65 runtime: call function via pointer in ax -; - - .export callax - -.code - -callax: - sta vec - stx vec+1 - jmp (vec) ; jump there - -.bss - -vec: - .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 5f360916c..4271fdc61 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -9,10 +9,10 @@ .proc _clock - ldy #0 ; Byte 3 is always zero - sty sreg+1 - sty sreg - + lda _tickcount+3 + sta sreg+1 + lda _tickcount+2 + sta sreg ldx _tickcount+1 lda _tickcount rts diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s deleted file mode 100644 index aa28833c2..000000000 --- a/libsrc/pce/condes.s +++ /dev/null @@ -1,96 +0,0 @@ -; -; Ullrich von Bassewitz, 20.11.2000 -; -; CC65 runtime: Support for calling module constructors/destructors -; -; The condes routine must be called with the table address in a/x and the -; size of the table in y. The current implementation limits the table size -; to 254 bytes (127 vectors) but this shouldn't be problem for now and may -; be changed later. -; -; libinit and libdone call condes with the predefined module constructor and -; destructor tables, they must be called from the platform specific startup -; code. - - - .export initlib, donelib, condes - - .import callax - .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ - .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ - - - -.code - -; -------------------------------------------------------------------------- -; Initialize library modules - -.proc initlib - - lda #<__CONSTRUCTOR_TABLE__ - ldx #>__CONSTRUCTOR_TABLE__ - ldy #<(__CONSTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Cleanup library modules - -.proc donelib - - lda #<__DESTRUCTOR_TABLE__ - ldx #>__DESTRUCTOR_TABLE__ - ldy #<(__DESTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Generic table call handler - -.proc condes - - sta getbyt+1 - stx getbyt+2 - sty index - -loop: ldy index - beq done - dey - jsr getbyt - tax - dey - jsr getbyt - sty index - jsr callax -.ifpc02 - bra loop -.else - jmp loop -.endif - -done: rts - -.endproc - - -; -------------------------------------------------------------------------- -; Data. The getbyte routine is placed in the data segment cause it's patched -; at runtime. - -.bss - -index: .byte 0 - -.data - -getbyt: -;;getbyt_: - lda $FFFF,y - rts diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 60801e172..9f113f515 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -5,7 +5,6 @@ .import vdc_init .export initconio - .export _conio_init .constructor initconio, 24 @@ -46,8 +45,6 @@ set_palette: stz VCE_DATA_LO stz VCE_DATA_HI - ; so it will get linked in -_conio_init: rts ;---------------------------------------------------------------------------- diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 06454998b..eab27ba5c 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -7,37 +7,38 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .export __STARTUP__ : absolute = 1 ; Mark as startup - .import initlib, donelib - .import push0, _main, zerobss - .import initheap - .import tmp1,tmp2,tmp3 + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup - .import __RAM_START__, __RAM_SIZE__ ; Linker generated -;; .import __SRAM_START__, __SRAM_SIZE__ ; Linker generated - .import __ROM0_START__, __ROM0_SIZE__ ; Linker generated - .import __ROM_START__, __ROM_SIZE__ ; Linker generated - .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ ; Linker generated - .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ ; Linker generated - .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ ; Linker generated - .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated - .import __BSS_SIZE__ + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 - .include "pce.inc" + ; 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__ - .importzp sp - .importzp ptr1,ptr2 + .include "pce.inc" + + .importzp sp + .importzp ptr1,ptr2 ; ------------------------------------------------------------------------ ; Create an empty LOWCODE segment to avoid linker warnings -.segment "LOWCODE" + .segment "LOWCODE" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. -.segment "STARTUP" + .segment "STARTUP" start: @@ -47,32 +48,32 @@ start: sei nop - csh ; set high speed CPU mode + csh ; set high speed CPU mode nop cld nop ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) + ldx #$FF ; Stack top ($21FF) txs ; at startup all MPRs are set to 0, so init them lda #$ff - tam #1 ; 0000-1FFF = Hardware page + tam #%00000001 ; 0000-1FFF = Hardware page lda #$F8 - tam #2 ; 2000-3FFF = Work RAM + tam #%00000010 ; 2000-3FFF = Work RAM ;lda #$F7 - ;tam #2 ; 4000-5FFF = Save RAM + ;tam #%00000100 ; 4000-5FFF = Save RAM ;lda #1 - ;tam #3 ; 6000-7FFF Page 2 + ;tam #%00001000 ; 6000-7FFF Page 2 ;lda #2 - ;tam #4 ; 8000-9FFF Page 3 + ;tam #%00010000 ; 8000-9FFF Page 3 ;lda #3 - ;tam #5 ; A000-BFFF Page 4 + ;tam #%00100000 ; A000-BFFF Page 4 ;lda #4 - ;tam #6 ; C000-DFFF Page 5 + ;tam #%01000000 ; C000-DFFF Page 5 ;lda #0 - ;tam #7 ; e000-fFFF hucard/syscard bank 0 + ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 ; Clear work RAM (2000-3FFF) stz <$00 @@ -88,110 +89,87 @@ start: .import vdc_init jsr vdc_init -;; jsr joy_init - ; Turn on background and VD interrupt/IRQ1 - lda #$05 sta IRQ_MASK ; IRQ1=on cli -; Clear the BSS data + ; Clear the BSS data + jsr zerobss - jsr zerobss - -; Copy the .data segment to RAM - - lda #<(__DATA_LOAD__) - ;;lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__) - ;;lda #<(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1 - lda #>(__DATA_LOAD__) - ;;lda #>(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1+1 - lda #<(__DATA_RUN__) - ;;lda #<(__SRAM_START__) - sta ptr2 - lda #>(__DATA_RUN__) - ;;lda #>(__SRAM_START__) - sta ptr2+1 - - ldx #>(__DATA_SIZE__) + ; Copy the .data segment to RAM + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 - dex - bne @l2 + dex + bne @l2 - ; copy remaining bytes + ; copy remaining bytes @s1: - - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 -; setup the stack + ; setup the stack + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 -; lda #<(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp -; lda #>(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 ; Set argument stack ptr + ; Init the Heap + jsr initheap -; Init the Heap - jsr initheap + ; Call module constructors + jsr initlib -;jmp * + ;; FIXME: this should be called from a constructor instead + .import initconio + jsr initconio -; Call module constructors + ; Pass an empty command line + jsr push0 ; argc + jsr push0 ; argv - jsr initlib - - ;; FIXME: this should be called from a constructor instead - .import initconio - jsr initconio - -; Pass an empty command line - - -;jmp * - - jsr push0 ; argc - jsr push0 ; argv -go: - ldy #4 ; Argument size - jsr _main ; call the users code - -; Call module destructors. This is also the _exit entry. + ldy #4 ; Argument size + jsr _main ; call the users code + ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors -; reset the PCEngine - - jmp start + ; reset the PCEngine (start over) + jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt +; FIXME: hooks should be provided so the user can abuse the IRQ ; ------------------------------------------------------------------------ _irq1: @@ -201,10 +179,13 @@ _irq1: inc _tickcount - bne @s + bne @s1 inc _tickcount+1 -@s: - + bne @s1 + inc _tickcount+2 + bne @s1 + inc _tickcount+3 +@s1: ; Acknowlege interrupt ldaio VDC_CTRL @@ -227,14 +208,10 @@ initmainargs: ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ - .segment "VECTORS" - ;;.org $fff6 - - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer - .word _nmi ; $fffc NMI - .word start ; $fffe reset - - + .segment "VECTORS" + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 6bc6bdf57..1aa98e16d 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -25,11 +25,6 @@ ; Button state masks (8 values) -;extern const unsigned char joy_masks[8]; - - .export _joy_masks - -_joy_masks: .byte $10 ; JOY_UP .byte $40 ; JOY_DOWN .byte $80 ; JOY_LEFT diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index e99b55122..cd91de97a 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -1,19 +1,23 @@ +PC-Engine (PCE) target support for cc65. this is still work in progress and +a couple of things need to be fixed: +-------------------------------------------------------------------------------- -joystick support should get verified on real hw, the masks for buttons may be -wrong. - -clock() does not work for unknown reasons - -get_tv() is a dummy function and always returns 0 +joystick support should get verified on real hw + - the masks for buttons may be wrong. + - 6 button gamepads are different and need slightly different code revers() is a dummy function, actual reverse output is not supported yet waitvblank() is missing +get_tv() is missing some graphical petscii chars should get added to the charset conio-init should get initialized from a constructor rather than always get -called from crt0 +called from crt0 (which for some reason doesnt work) -> see conio.s, it should +get linked if _any_ of the conio function is used + +interruptor support in crt0 (and cfg) is missing -------------------------------------------------------------------------------- @@ -29,3 +33,16 @@ w/s/a/d up/down/left/right numpad 2 (?) button numpad 3 (?) button enter (start) button + +-------------------------------------------------------------------------------- +some useful resources on PCE coding: + +http://blog.blockos.org/?tag=pc-engine +http://pcedev.blockos.org/viewforum.php?f=5 +http://www.romhacking.net/?page=documents&category=&platform=4&game=&author=&perpage=20&level=&title=&desc=&docsearch=Go +http://archaicpixels.com/Main_Page + +http://www.magicengine.com/mkit/doc.html + +https://github.com/uli/huc +http://www.zeograd.com/parse.php?src=hucf \ No newline at end of file diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/scrsize.s similarity index 100% rename from libsrc/pce/_scrsize.s rename to libsrc/pce/scrsize.s diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile new file mode 100644 index 000000000..364074180 --- /dev/null +++ b/testcode/lib/pce/Makefile @@ -0,0 +1,12 @@ + +all: conio.pce + +conio.pce: conio.c + ../../../bin/cl65 -t pce conio.c ../../../joy/pce-stdjoy.joy --mapfile conio.map -o conio.pce + +clean: + $(RM) conio.pce + +test: conio.pce + mednafen -force_module pce conio.pce + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 306eb1ebb..0c5c89c57 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -9,6 +9,7 @@ void main(void) { int stackvar = 42; int i, j; + clock_t clk; joy_install(&joy_static_stddrv); @@ -39,7 +40,9 @@ void main(void) ++datavar; ++stackvar; gotoxy(0,8); - cprintf("clock: %08x", clock()); + clk = clock(); + cprintf("clock: %08lx", clk); + for (i = 0; i < 4; ++i) { gotoxy(0, 12 + i); From 515a61a302a1923de5816c8418f0af56bb4dc77e Mon Sep 17 00:00:00 2001 From: mrdudz Date: Mon, 13 Jul 2015 12:10:09 +0200 Subject: [PATCH 08/28] added imports for conio init to conio functions, so the constructor will get linked and called automatically --- libsrc/pce/clrscr.s | 5 +++++ libsrc/pce/color.s | 6 ++++++ libsrc/pce/cputc.s | 6 ++++++ libsrc/pce/crt0.s | 4 ---- libsrc/pce/gotoxy.s | 5 +++++ libsrc/pce/kplot.s | 5 +++++ libsrc/pce/readme.txt | 7 +++---- libsrc/pce/revers.s | 8 ++++++++ libsrc/pce/scrsize.s | 2 ++ testcode/lib/pce/conio.c | 4 ++-- 10 files changed, 42 insertions(+), 10 deletions(-) diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 93628ddd8..59fda4f2e 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -23,3 +23,8 @@ colloop: lda #' ' rts +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 0ec35f5b3..03d93b186 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -55,3 +55,9 @@ colors: ; G R B .word ((7<<6)+(4<<3)+(4)) ; d light green .word ((4<<6)+(4<<3)+(7)) ; e light blue .word ((6<<6)+(6<<3)+(6)) ; f light gray + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index ec63b7565..e503ee6f2 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -91,3 +91,9 @@ putchar: staio VDC_DATA_HI rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index eab27ba5c..e67039d43 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -149,10 +149,6 @@ start: ; Call module constructors jsr initlib - ;; FIXME: this should be called from a constructor instead - .import initconio - jsr initconio - ; Pass an empty command line jsr push0 ; argc jsr push0 ; argv diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index 24f917cd6..c6b937177 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -13,4 +13,9 @@ _gotoxy: sta CURS_X ; Set X jmp plot ; Set the cursor position +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index beb151a7b..eb4e79e04 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -29,4 +29,9 @@ _plothi: .byte >($0000+(line*$80)) .endrepeat +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index cd91de97a..c7b3aed3d 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -13,12 +13,11 @@ get_tv() is missing some graphical petscii chars should get added to the charset -conio-init should get initialized from a constructor rather than always get -called from crt0 (which for some reason doesnt work) -> see conio.s, it should -get linked if _any_ of the conio function is used - interruptor support in crt0 (and cfg) is missing +conio lacks support for different screen sizes, which could be used with +different video modes + -------------------------------------------------------------------------------- a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index c39a9f843..d3e6f8930 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,13 @@ +; FIXME: actual revers output is not supported yet + .export _revers _revers: lda #0 rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/scrsize.s b/libsrc/pce/scrsize.s index 6e2b84a41..254676aae 100644 --- a/libsrc/pce/scrsize.s +++ b/libsrc/pce/scrsize.s @@ -8,6 +8,8 @@ _screensize: ldy ysize rts +; FIXME: changing the video mode allows for different screen sizes + .rodata .export xsize, ysize diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 0c5c89c57..993d93597 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -42,7 +42,7 @@ void main(void) gotoxy(0,8); clk = clock(); cprintf("clock: %08lx", clk); - + for (i = 0; i < 4; ++i) { gotoxy(0, 12 + i); @@ -58,4 +58,4 @@ void main(void) } } for(;;); -} \ No newline at end of file +} From 83391ab67c8aacf260b32888849dc01f0ae8fe8d Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 14 Jul 2015 17:22:47 +0200 Subject: [PATCH 09/28] some more tweaking, added docs page --- asminc/pce.inc | 12 ++- doc/index.sgml | 3 + doc/pce.sgml | 198 +++++++++++++++++++++++++++++++++++++++ libsrc/pce/conio.s | 18 ++-- libsrc/pce/readme.txt | 2 +- testcode/lib/pce/conio.c | 12 +++ 6 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 doc/pce.sgml diff --git a/asminc/pce.inc b/asminc/pce.inc index 6d1541d64..767f1a529 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -52,12 +52,22 @@ VDC_DATA_HI = $0003 ; bitmap of the palette data is this: 0000000gggrrrbbb. ; You can read and write the DAC-registers. -VCE_CTRL = $0400 ; write$00 to reset +VCE = $0400 ; base + +VCE_CTRL = $0400 ; write$00 to reset VCE_ADDR_LO = $0402 ; LSB of byte offset into palette VCE_ADDR_HI = $0403 ; MSB of byte offset into palette VCE_DATA_LO = $0404 ; LSB of 16-bit palette data VCE_DATA_HI = $0405 ; MSB of 16-bit palette data +; programmable sound generator (PSG) + +PSG = $0800 ; base + +; timer + +TIMER = $0c00 ; base + TIMER_COUNT = $0c00 TIMER_CTRL = $0c01 diff --git a/doc/index.sgml b/doc/index.sgml index 921b8c03d..eb13c9af5 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -137,6 +137,9 @@ Topics specific to the Ohio Scientific machines. + + Topics specific to NEC PC-Engine (TurboGrafx) Console. + Topics specific to the Commodore PET machines. diff --git a/doc/pce.sgml b/doc/pce.sgml new file mode 100644 index 000000000..4c395ae43 --- /dev/null +++ b/doc/pce.sgml @@ -0,0 +1,198 @@ + + +
+ +PC-Engine (TurboGrafx) System specific information for cc65 +<author> +<url url="mailto:groepaz@gmx.net" name="Groepaz/Hitmen"> +<date>2015-07-14 + +<abstract> +An overview over the PCE runtime system as it is implemented for the +cc65 C compiler. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview<p> + +This file contains an overview of the PCE runtime system as it comes +with the cc65 C compiler. It describes the memory layout, PCE specific header +files, available drivers, and any pitfalls specific to that platform. + +Please note that PCE specific functions are just mentioned here, they are +described in detail in the separate <url url="funcref.html" name="function +reference">. Even functions marked as "platform dependent" may be available on +more than one platform. Please see the function reference for more +information. + + +<sect>Binary format<p> + +The standard binary output format generated by the linker for the PCE target +is a cartridge image with no header. It is of course possible to change this +behaviour by using a modified startup file and linker config. + +<sect>Memory layout<p> + +cc65 generated programs with the default setup run with the I/O area and a +CHR bank enabled, which gives a usable memory range of $8000 - $FFF3. +All boot ROM entry points may be called directly without additional code. + +Special locations: + +<descrip> + <tag/Text screen and Font/ + The text screen is located at VRAM $0000, + the Font is located at VRAM $2000. + + <tag/Stack/ + The C runtime stack is located in system RAM at $3FFF and growing downwards. + + <tag/BSS and Data/ + + The BSS (uninitialized variables) and Data (initialized variables) sections are + placed one after the other into system RAM at $2000. + + <tag/Heap/ + The C heap is located after the end of the Data section and grows towards the C + runtime stack. + + <tag/Code/ + The startup code is located at $E000 in the System/Hardware bank. Further + code can be placed in other ROM banks, this must be done manually however. + +</descrip><p> + + + +<sect>Platform specific header files<p> + +Programs containing PCE specific code may use the <tt/pce.h/ header file. + + +<sect1>PCE specific functions<p> + +<itemize> +<item>waitvblank +<item>get_tv +</itemize> + + + +<sect1>Hardware access<p> + +The following pseudo variables declared in the <tt/pce.inc/ include file do +allow access to hardware located in the address space. + +<descrip> + + <tag><tt/PSG/</tag> + The <tt/PSG/ defines allow access to the PSG chip (Programmable Sound Generator). + + <tag><tt/VCE/</tag> + The <tt/VCE/ defines allow access to the VCE chip (Video Color Encoder). + + <tag><tt/VDC/</tag> + The <tt/VDC/ defines allow access to the VDC chip (Video Display Controller). + +</descrip><p> + + + +<sect>Loadable drivers<p> + +All drivers must be statically linked because no file I/O is available. +The names in the parentheses denote the symbols to be used for static linking of the drivers. + + +<sect1>Graphics drivers<p> + +<descrip> + +No TGI graphics drivers are currently available for the PCE. + +</descrip><p> + + +<sect1>Extended memory drivers<p> + +No extended memory drivers are currently available for the PCE. + + +<sect1>Joystick drivers<p> + +<descrip> + + <tag><tt/pce-stdjoy.joy (pce_stdjoy)/</tag> + A joystick driver for the standard two buttons joypad is available. + +</descrip><p> + + +<sect1>Mouse drivers<p> + +No mouse drivers are currently available for the PCE. + + +<sect1>RS232 device drivers<p> + +No serial drivers are currently available for the PCE. + + + +<sect>Limitations<p> + +<sect1>Disk I/O<p> + +The existing library for the PCE doesn't implement C file +I/O. There are no hacks for the <tt/read()/ and <tt/write()/ routines. + +To be more concrete, this limitation means that you cannot use any of the +following functions (and a few others): + +<itemize> +<item>fclose +<item>fopen +<item>fread +<item>fprintf +<item>fputc +<item>fscanf +<item>fwrite +<item>... +</itemize> + + + +<sect>Other hints<p> + + + +<sect>License<p> + +This software is provided 'as-is', without any expressed 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: + +<enum> +<item> 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. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> + + + diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 9f113f515..2556833b0 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -59,18 +59,18 @@ conio_init: st2 #>$2000 ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 clc ; increment font pointer lda ptr1 @@ -90,9 +90,9 @@ fillloop: st1 #$00 bne charloop ; next character ldx #0 - stx BGCOLOR + stx BGCOLOR inx - stx CHARCOLOR + stx CHARCOLOR rts diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index c7b3aed3d..5b170b7f7 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -44,4 +44,4 @@ http://archaicpixels.com/Main_Page http://www.magicengine.com/mkit/doc.html https://github.com/uli/huc -http://www.zeograd.com/parse.php?src=hucf \ No newline at end of file +http://www.zeograd.com/parse.php?src=hucf diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 993d93597..88c343af2 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -2,6 +2,8 @@ #include <conio.h> #include <time.h> #include <joystick.h> +#include <string.h> +#include <stdlib.h> static int datavar = 10; @@ -10,6 +12,7 @@ void main(void) int stackvar = 42; int i, j; clock_t clk; + char *p; joy_install(&joy_static_stddrv); @@ -31,6 +34,15 @@ void main(void) gotoxy(0,10); cprintf("Found %d Joysticks.", j); + for (i = 0; i < 4; ++i) { + gotoxy(0, 17 + i); + p = malloc(16); + memcpy(p, "01234567890abcdef", 16); + cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] + ); + } + for(;;) { gotoxy(13,4); From ac27ed301aa36183825b98dc5c22635ad1e1bc9f Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 14 Jul 2015 19:55:41 +0200 Subject: [PATCH 10/28] _tickcount -> tickcount --- asminc/pce.inc | 2 +- libsrc/pce/clock.s | 9 +++++---- libsrc/pce/crt0.s | 8 ++++---- libsrc/pce/readme.txt | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 767f1a529..424dd8c36 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -11,7 +11,7 @@ CRAM_PTR = $34 ;2 CHARCOLOR = $36 RVS = $37 BGCOLOR = $38 -_tickcount = $39 ;4 +tickcount = $39 ;4 screenrows = (224/8) charsperline = (512/8) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 4271fdc61..6f939f078 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -6,15 +6,16 @@ .export _clock .importzp sreg +;; .importzp tickcount .proc _clock - lda _tickcount+3 + lda tickcount+3 sta sreg+1 - lda _tickcount+2 + lda tickcount+2 sta sreg - ldx _tickcount+1 - lda _tickcount + ldx tickcount+1 + lda tickcount rts .endproc diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index e67039d43..1a7a04e0b 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -174,13 +174,13 @@ _irq1: phy - inc _tickcount + inc tickcount bne @s1 - inc _tickcount+1 + inc tickcount+1 bne @s1 - inc _tickcount+2 + inc tickcount+2 bne @s1 - inc _tickcount+3 + inc tickcount+3 @s1: ; Acknowlege interrupt ldaio VDC_CTRL diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 5b170b7f7..d07150913 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -14,6 +14,7 @@ get_tv() is missing some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing +- clock() should be hooked to a VBL interrupt conio lacks support for different screen sizes, which could be used with different video modes From c3d45e4c4767be66388ab719b3428fc4bcbd7b84 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 15 Jul 2015 13:18:12 +0200 Subject: [PATCH 11/28] fixed issues found by gregg --- asminc/pce.inc | 21 ++---------- include/pce.h | 3 -- include/time.h | 4 +++ libsrc/pce/clrscr.s | 8 ++--- libsrc/pce/conio.s | 24 ++++++------- libsrc/pce/cputc.s | 21 ++++++------ libsrc/pce/crt0.s | 84 ++++++++++++++++++++------------------------- libsrc/pce/vdc.s | 10 +++--- 8 files changed, 76 insertions(+), 99 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 424dd8c36..98364815b 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -42,6 +42,9 @@ VDC_DESR =16 ; (DMA) Destination Register VDC_LENR =17 ; (DMA) Length Register VDC_SATB =18 ; Sprite Attribute Table +; VDC port +; Note: absolute addressing mode must be used when writing to this port + VDC_CTRL = $0000 VDC_DATA_LO = $0002 VDC_DATA_HI = $0003 @@ -79,24 +82,6 @@ IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 CDR_MEM_ENABLE = $1807 -;; lda abs -.macro ldaio arg1 - .byte $ad - .word arg1 -.endmacro - -;; sta abs -.macro staio arg1 - .byte $8d - .word arg1 -.endmacro - -;; stz abs -.macro stzio arg1 - .byte $9c - .word arg1 -.endmacro - ; Write VDC register .macro VREG arg1,arg2 st0 #arg1 diff --git a/include/pce.h b/include/pce.h index 912e0157b..613da2b0d 100644 --- a/include/pce.h +++ b/include/pce.h @@ -65,9 +65,6 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F -#define CLOCKS_PER_SEC 50 // FIXME: is this correct? -#define CLK_TCK 50 // FIXME: is this correct? - #define TV_NTSC 0 #define TV_PAL 1 #define TV_OTHER 2 diff --git a/include/time.h b/include/time.h index c70ffa718..8fc787228 100644 --- a/include/time.h +++ b/include/time.h @@ -99,6 +99,10 @@ unsigned _clocks_per_sec (void); #elif defined(__NES__) # define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50 /* ANSI */ +#elif defined(__PCE__) +/* FIXME: we likely need to read it at runtime */ +# define CLK_TCK 50 /* POSIX */ +# define CLOCKS_PER_SEC 50 /* ANSI */ #elif defined(__GEOS__) # define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1 /* ANSI */ diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 59fda4f2e..9279f1e25 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -11,10 +11,10 @@ _clrscr: st0 #VDC_VWR ldy #$40 rowloop: ldx #$80 -colloop: lda #' ' - staio VDC_DATA_LO - lda #$02 - staio VDC_DATA_HI +colloop: lda #' ' + sta a:VDC_DATA_LO + lda #$02 + sta a:VDC_DATA_HI dex bne colloop diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 2556833b0..a8a9da244 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -4,8 +4,6 @@ .import psg_init .import vdc_init - .export initconio - .constructor initconio, 24 .macpack longbranch @@ -28,17 +26,19 @@ set_palette: ldx #0 @lp: - .repeat 16 - lda colors,x + ldy #16 +@lp1: + lda colors,x sta VCE_DATA_LO - lda colors+1,x + lda colors+1,x sta VCE_DATA_HI - .endrepeat + dey + bne @lp1 inx inx - cpx #16*2 - jne @lp + cpx #16*2 + jne @lp stz VCE_ADDR_LO stz VCE_ADDR_HI @@ -68,9 +68,9 @@ conio_init: ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: - lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + lda (ptr1) + sta a:VDC_DATA_LO ; bitplane 0 + stz a:VDC_DATA_HI ; bitplane 1 clc ; increment font pointer lda ptr1 @@ -89,7 +89,7 @@ fillloop: st1 #$00 dey bne charloop ; next character - ldx #0 + ldx #0 stx BGCOLOR inx stx CHARCOLOR diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index e503ee6f2..e2e345ac2 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -69,26 +69,25 @@ putchar: st0 #VDC_MAWR ; Memory Adress Write lda SCREEN_PTR - staio VDC_DATA_LO + sta a:VDC_DATA_LO lda SCREEN_PTR+1 - staio VDC_DATA_HI + sta a:VDC_DATA_HI st0 #VDC_VWR ; VWR txa - staio VDC_DATA_LO ; character + sta a:VDC_DATA_LO ; character - lda CHARCOLOR + lda CHARCOLOR - asl a - asl a - asl a - asl a + asl a + asl a + asl a + asl a - and #$f0 - ora #$02 - staio VDC_DATA_HI + ora #$02 + sta a:VDC_DATA_HI rts diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 1a7a04e0b..e456bdeac 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -30,11 +30,6 @@ .importzp sp .importzp ptr1,ptr2 -; ------------------------------------------------------------------------ -; Create an empty LOWCODE segment to avoid linker warnings - - .segment "LOWCODE" - ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. @@ -42,7 +37,7 @@ start: -; setup the CPU and System-IRQ + ; setup the CPU and System-IRQ ; Initialize CPU @@ -96,58 +91,55 @@ start: cli ; Clear the BSS data - jsr zerobss + jsr zerobss ; Copy the .data segment to RAM - lda #<(__DATA_LOAD__) - sta ptr1 - lda #>(__DATA_LOAD__) - sta ptr1+1 - lda #<(__DATA_RUN__) - sta ptr2 - lda #>(__DATA_RUN__) - sta ptr2+1 + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 - ldx #>(__DATA_SIZE__) + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages ; copy one page - ldy #0 + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y + lda (ptr1),y + sta (ptr2),y iny - bne @l1 + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 dex - bne @l2 + bne @l2 ; copy remaining bytes @s1: ; copy one page - ldy #0 + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y + lda (ptr1),y + sta (ptr2),y iny - cpy #<(__DATA_SIZE__) - bne @l3 + cpy #<(__DATA_SIZE__) + bne @l3 ; setup the stack - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 - - ; Init the Heap - jsr initheap + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 ; Call module constructors - jsr initlib + jsr initlib ; Pass an empty command line jsr push0 ; argc @@ -158,7 +150,7 @@ start: ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors ; reset the PCEngine (start over) jmp start @@ -174,16 +166,16 @@ _irq1: phy - inc tickcount - bne @s1 - inc tickcount+1 - bne @s1 - inc tickcount+2 - bne @s1 - inc tickcount+3 + inc tickcount + bne @s1 + inc tickcount+1 + bne @s1 + inc tickcount+2 + bne @s1 + inc tickcount+3 @s1: ; Acknowlege interrupt - ldaio VDC_CTRL + lda a:VDC_CTRL ply plx diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index d1ead937e..0f42fe1b0 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -6,7 +6,7 @@ HIRES = 1 .export vdc_init vdc_init: - ldaio VDC_CTRL + lda a:VDC_CTRL VREG $00, $0000 ; MAWR VREG $01, $0000 ; MARR @@ -20,21 +20,21 @@ vdc_init: VREG $0E, $000C ; CRTC - VDE VREG $0F, $0000 ; DCR - .if HIRES +.if HIRES VREG $0A, $0C02 ; CRTC - HSR VREG $0B, $043C ; CRTC - HDS lda #$06 sta VCE_CTRL - .else +.else VREG $0A, $0202 ; CRTC - HSR VREG $0B, $041F ; CRTC - HDS lda #$04 sta VCE_CTRL - .endif +.endif - ldaio VDC_CTRL + lda a:VDC_CTRL rts From 1414411bba07a7c15c75dbf46fbb7b227d82161e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 15 Jul 2015 19:46:26 +0200 Subject: [PATCH 12/28] added waitvblank and fixed get_tv --- doc/pce.sgml | 4 ++-- include/pce.h | 4 ++-- libsrc/pce/readme.txt | 3 --- libsrc/pce/waitvblank.s | 18 ++++++++++++++++++ testcode/lib/pce/conio.c | 19 +++++++++++++++++-- 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 libsrc/pce/waitvblank.s diff --git a/doc/pce.sgml b/doc/pce.sgml index 4c395ae43..2d14e8361 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -77,8 +77,8 @@ Programs containing PCE specific code may use the <tt/pce.h/ header file. <sect1>PCE specific functions<p> <itemize> -<item>waitvblank -<item>get_tv +<item>waitvblank</item> +<item>get_tv</item> (since all PCE systems are NTSC, this always returns TV_NTSC) </itemize> diff --git a/include/pce.h b/include/pce.h index 613da2b0d..74b6409e1 100644 --- a/include/pce.h +++ b/include/pce.h @@ -83,8 +83,8 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ void waitvblank (void); /* Wait for the vertical blanking */ -/* FIXME: not implemented */ -unsigned char get_tv (void); +/* all PCE are NTSC */ +#define get_tv() TV_NTSC /* Return the video mode the machine is using. */ diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index d07150913..b201893d1 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -8,9 +8,6 @@ joystick support should get verified on real hw revers() is a dummy function, actual reverse output is not supported yet -waitvblank() is missing -get_tv() is missing - some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s new file mode 100644 index 000000000..2ded2835e --- /dev/null +++ b/libsrc/pce/waitvblank.s @@ -0,0 +1,18 @@ +; +; void waitvblank (void); +; + + .include "pce.inc" + + .export _waitvblank +;; .importzp tickcount + +.proc _waitvblank + + lda tickcount +@lp: cmp tickcount + beq @lp + rts + +.endproc + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 88c343af2..92431d142 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -43,8 +43,22 @@ void main(void) ); } - for(;;) - { + i = get_tv(); + gotoxy(30,0); + cputs("TV Mode: "); + switch(i) { + case TV_NTSC: + cputs("NTSC"); + break; + case TV_PAL: + cputs("PAL"); + break; + case TV_OTHER: + cputs("OTHER"); + break; + } + + for(;;) { gotoxy(13,4); cprintf("%02x", datavar); gotoxy(13,5); @@ -68,6 +82,7 @@ void main(void) (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); } + waitvblank(); } for(;;); } From 21ef6b8510ccd640b9099966424c174747de1524 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 16:00:32 +0200 Subject: [PATCH 13/28] fixed screensize, timertick, revers mode --- asminc/pce.inc | 3 +-- include/time.h | 5 ++--- libsrc/pce/{scrsize.s => _scrsize.s} | 9 ++++---- libsrc/pce/conio.s | 33 ++++++++++++++++++++++------ libsrc/pce/cputc.s | 3 ++- libsrc/pce/readme.txt | 5 ----- libsrc/pce/revers.s | 24 +++++++++++++++----- testcode/lib/pce/conio.c | 31 ++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 27 deletions(-) rename libsrc/pce/{scrsize.s => _scrsize.s} (59%) diff --git a/asminc/pce.inc b/asminc/pce.inc index 98364815b..851b2f32a 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -14,8 +14,7 @@ BGCOLOR = $38 tickcount = $39 ;4 screenrows = (224/8) -charsperline = (512/8) -xsize = charsperline +charsperline = 61 CH_HLINE = 7 CH_VLINE = 7 diff --git a/include/time.h b/include/time.h index 8fc787228..12f130f52 100644 --- a/include/time.h +++ b/include/time.h @@ -100,9 +100,8 @@ unsigned _clocks_per_sec (void); # define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50 /* ANSI */ #elif defined(__PCE__) -/* FIXME: we likely need to read it at runtime */ -# define CLK_TCK 50 /* POSIX */ -# define CLOCKS_PER_SEC 50 /* ANSI */ +# define CLK_TCK 60 /* POSIX */ +# define CLOCKS_PER_SEC 60 /* ANSI */ #elif defined(__GEOS__) # define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1 /* ANSI */ diff --git a/libsrc/pce/scrsize.s b/libsrc/pce/_scrsize.s similarity index 59% rename from libsrc/pce/scrsize.s rename to libsrc/pce/_scrsize.s index 254676aae..8dab2cf7b 100644 --- a/libsrc/pce/scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -1,9 +1,10 @@ ; ; Screen size variables ; + .include "pce.inc" - .export _screensize -_screensize: + .export screensize +screensize: ldx xsize ldy ysize rts @@ -13,5 +14,5 @@ _screensize: .rodata .export xsize, ysize -xsize: .byte 64 -ysize: .byte 28 +xsize: .byte charsperline +ysize: .byte screenrows diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index a8a9da244..4fb3b1394 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -51,7 +51,7 @@ set_palette: ; ;---------------------------------------------------------------------------- - .importzp ptr1 + .importzp ptr1, tmp1 conio_init: ; Load font st0 #VDC_MAWR @@ -65,10 +65,35 @@ conio_init: sta ptr1+1 st0 #VDC_VWR ; VWR + + lda #0 + sta tmp1 + jsr copy + + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 + + lda #$ff + sta tmp1 + jsr copy + + + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR + + + rts + +copy: ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: lda (ptr1) + eor tmp1 sta a:VDC_DATA_LO ; bitplane 0 stz a:VDC_DATA_HI ; bitplane 1 @@ -89,12 +114,6 @@ fillloop: st1 #$00 dey bne charloop ; next character - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR - - rts .rodata diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index e2e345ac2..918f39e29 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -7,6 +7,7 @@ .export newline, plot .import popa, _gotoxy .import PLOT + .import xsize .importzp tmp3,tmp4 @@ -38,7 +39,7 @@ cputdirect: advance: ldy CURS_X iny - cpy #xsize + cpy xsize bne L3 jsr newline ; new line ldy #0 ; + cr diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index b201893d1..7dd857f21 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -6,16 +6,11 @@ joystick support should get verified on real hw - the masks for buttons may be wrong. - 6 button gamepads are different and need slightly different code -revers() is a dummy function, actual reverse output is not supported yet - some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt -conio lacks support for different screen sizes, which could be used with -different video modes - -------------------------------------------------------------------------------- a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index d3e6f8930..061023d09 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,10 +1,24 @@ -; FIXME: actual revers output is not supported yet + .include "pce.inc" - .export _revers -_revers: - lda #0 - rts + .export _revers + +.proc _revers + + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts + +.endproc ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 92431d142..b94c91877 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -13,10 +13,12 @@ void main(void) int i, j; clock_t clk; char *p; + unsigned char xsize, ysize, n; joy_install(&joy_static_stddrv); clrscr(); + screensize(&xsize, &ysize); cputs("hello world"); cputsxy(0, 2, "colors:" ); @@ -43,6 +45,25 @@ void main(void) ); } + gotoxy(0,ysize - 1); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + + gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + for (i = 0; i < (xsize * 5); ++i) { + cputc('#'); + } + gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); + for (i = 0; i < 256; ++i) { + if ((i != '\n') && (i != '\r')) { + cputc(i); + } + } + i = get_tv(); gotoxy(30,0); cputs("TV Mode: "); @@ -57,6 +78,7 @@ void main(void) cputs("OTHER"); break; } + cprintf(" %dx%d", xsize, ysize); for(;;) { gotoxy(13,4); @@ -82,7 +104,16 @@ void main(void) (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); } + + gotoxy(xsize - 10, 3); + j = (n >> 5) & 1; + revers(j); + cputc(j ? 'R' : ' '); + cputs(" revers"); + revers(0); + waitvblank(); + ++n; } for(;;); } From d229d51be5901d7b57ea831c663c130d83a9f8e9 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 16:54:40 +0200 Subject: [PATCH 14/28] make sure clocktick starts at zero --- libsrc/pce/clock.s | 32 +++++++++++++++++++++----------- libsrc/pce/crt0.s | 4 ++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 6f939f078..5d0aa78f4 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -2,20 +2,30 @@ ; clock_t clock (void); ; - .include "pce.inc" + .include "pce.inc" - .export _clock - .importzp sreg -;; .importzp tickcount + .export _clock + .importzp sreg +;; .importzp tickcount .proc _clock - lda tickcount+3 - sta sreg+1 - lda tickcount+2 - sta sreg - ldx tickcount+1 - lda tickcount - rts + lda tickcount+3 + sta sreg+1 + lda tickcount+2 + sta sreg + ldx tickcount+1 + lda tickcount + rts .endproc + + .constructor initclock, 24 + +initclock: + lda #0 + ldx #3 +@lp: sta tickcount,x + dex + bpl @lp + rts \ No newline at end of file diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index e456bdeac..2b8455a59 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -88,8 +88,6 @@ start: lda #$05 sta IRQ_MASK ; IRQ1=on - cli - ; Clear the BSS data jsr zerobss @@ -141,6 +139,8 @@ start: ; Call module constructors jsr initlib + cli ; allow IRQ only after constructors have run + ; Pass an empty command line jsr push0 ; argc jsr push0 ; argv From 3119be2a1e0d174b7ff4ee7bf485bab3122d26a6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 17:33:00 +0200 Subject: [PATCH 15/28] added some cbm-like gfx chars to draw lines and boxes --- include/pce.h | 26 +++++----- libsrc/pce/readme.txt | 2 - libsrc/pce/vga.inc | 112 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 114 insertions(+), 26 deletions(-) diff --git a/include/pce.h b/include/pce.h index 74b6409e1..27f70de0f 100644 --- a/include/pce.h +++ b/include/pce.h @@ -36,16 +36,20 @@ # error This module may only be used when compiling for the PCE! #endif -/* FIXME: the respective characters are not present in the VGA charset (yet) */ -#define CH_CROSS 0x10 +#define CH_HLINE 1 +#define CH_VLINE 2 +#define CH_CROSS 3 +#define CH_ULCORNER 4 +#define CH_URCORNER 5 +#define CH_LLCORNER 6 +#define CH_LRCORNER 7 +#define CH_TTEE 8 +#define CH_BTEE 9 +#define CH_LTEE 10 +#define CH_RTEE 11 -#define CH_RTEE 0x17 -#define CH_LTEE 0x0f - -#define CH_ULCORNER 0x10 -#define CH_URCORNER 0x10 -#define CH_LLCORNER 0x10 -#define CH_LRCORNER 0x10 +#define CH_ENTER 13 +#define CH_PI 18 /* Color defines (CBM compatible, for conio) */ #define COLOR_BLACK 0x00 @@ -79,14 +83,12 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_START 6 #define JOY_SELECT 7 -/* FIXME: not implemented */ void waitvblank (void); /* Wait for the vertical blanking */ -/* all PCE are NTSC */ +/* NOTE: all PCE are NTSC */ #define get_tv() TV_NTSC /* Return the video mode the machine is using. */ - /* End of pce.h */ #endif diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 7dd857f21..243a07417 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -6,8 +6,6 @@ joystick support should get verified on real hw - the masks for buttons may be wrong. - 6 button gamepads are different and need slightly different code -some graphical petscii chars should get added to the charset - interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index 2f9408f9a..b5c4b27fd 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -2,18 +2,106 @@ ; VGA charset for the PC-Engine conio implementation .byte $00, $00, $00, $00, $00, $00, $00, $00 - .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E - .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E - .byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 - .byte $10, $38, $7C, $FE, $7C, $38, $10, $00 - .byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C - .byte $10, $10, $38, $7C, $FE, $7C, $38, $7C - .byte $00, $00, $18, $3C, $3C, $18, $00, $00 - .byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF - .byte $00, $3C, $66, $42, $42, $66, $3C, $00 - .byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF - .byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 - .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + ;;.byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11111111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11111111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00011111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11110000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00011111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11110000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11111111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11111111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00011111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11110000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 From e77060458a3517baba44d0ce2efa0b3a6756c07c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 20:15:05 +0200 Subject: [PATCH 16/28] fixed joypad bits --- include/pce.h | 4 ++-- libsrc/pce/joy/pce-stdjoy.s | 8 ++++---- libsrc/pce/readme.txt | 4 +--- testcode/lib/pce/conio.c | 6 ++++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/pce.h b/include/pce.h index 27f70de0f..6f18ba501 100644 --- a/include/pce.h +++ b/include/pce.h @@ -80,8 +80,8 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 +#define JOY_SELECT 6 +#define JOY_RUN 7 void waitvblank (void); /* Wait for the vertical blanking */ diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 1aa98e16d..592793250 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -29,10 +29,10 @@ .byte $40 ; JOY_DOWN .byte $80 ; JOY_LEFT .byte $20 ; JOY_RIGHT - .byte $02 ; JOY_FIRE A ; FIXME: is this correct? - .byte $01 ; JOY_FIRE B ; FIXME: is this correct? - .byte $04 ; JOY_START ; FIXME: is this correct? - .byte $08 ; JOY_SELECT ; FIXME: is this correct? + .byte $01 ; JOY_FIRE_A + .byte $02 ; JOY_FIRE_B + .byte $04 ; JOY_SELECT + .byte $08 ; JOY_RUN ; Jump table. diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 243a07417..a822205d4 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -2,9 +2,7 @@ PC-Engine (PCE) target support for cc65. this is still work in progress and a couple of things need to be fixed: -------------------------------------------------------------------------------- -joystick support should get verified on real hw - - the masks for buttons may be wrong. - - 6 button gamepads are different and need slightly different code +- 6 button gamepads are different and need slightly different code interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index b94c91877..f5231dba6 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -95,14 +95,16 @@ void main(void) { gotoxy(0, 12 + i); j = joy_read (i); - cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s", + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", i, j, (j & joy_masks[JOY_UP])? " up " : " ---- ", (j & joy_masks[JOY_DOWN])? " down " : " ---- ", (j & joy_masks[JOY_LEFT])? " left " : " ---- ", (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", + (j & joy_masks[JOY_SELECT])? "select" : " ---- ", + (j & joy_masks[JOY_RUN])? " run " : " ---- "); } gotoxy(xsize - 10, 3); From 996c7b493e6111533b8c919b98b49cf7ce29bc45 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 21:39:13 +0200 Subject: [PATCH 17/28] moved all notes into regular documentation --- doc/pce.sgml | 25 +++++++++++++++++++++++-- libsrc/pce/readme.txt | 36 ------------------------------------ 2 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 libsrc/pce/readme.txt diff --git a/doc/pce.sgml b/doc/pce.sgml index 2d14e8361..74692ce16 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -130,6 +130,8 @@ No extended memory drivers are currently available for the PCE. <tag><tt/pce-stdjoy.joy (pce_stdjoy)/</tag> A joystick driver for the standard two buttons joypad is available. + Note that the japanese 6-button pad is currently not supported. + </descrip><p> @@ -146,6 +148,10 @@ No serial drivers are currently available for the PCE. <sect>Limitations<p> +<itemize> +<item>interruptor support in crt0 (and cfg) is missing +</itemize> + <sect1>Disk I/O<p> The existing library for the PCE doesn't implement C file @@ -155,6 +161,7 @@ To be more concrete, this limitation means that you cannot use any of the following functions (and a few others): <itemize> +<item>printf <item>fclose <item>fopen <item>fread @@ -165,11 +172,25 @@ following functions (and a few others): <item>... </itemize> - - <sect>Other hints<p> +<itemize> +<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.sourceforge.net">) +</itemize> +some useful resources on PCE coding: + +<itemize> +<item><url url="http://blog.blockos.org/?tag=pc-engine"> +<item><url url="http://pcedev.blockos.org/viewforum.php?f=5"> +<item><url url="http://www.romhacking.net/?page=documents&category=&platform=4&:game=&author=&perpage=20&level=&title=&desc=&docsearch=Go"> +<item><url url="http://archaicpixels.com/Main_Page"> + +<item><url url="http://www.magicengine.com/mkit/doc.html"> + +<item><url url="https://github.com/uli/huc"> +<item><url url="http://www.zeograd.com/parse.php?src=hucf"> +</itemize> <sect>License<p> diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt deleted file mode 100644 index a822205d4..000000000 --- a/libsrc/pce/readme.txt +++ /dev/null @@ -1,36 +0,0 @@ -PC-Engine (PCE) target support for cc65. this is still work in progress and -a couple of things need to be fixed: --------------------------------------------------------------------------------- - -- 6 button gamepads are different and need slightly different code - -interruptor support in crt0 (and cfg) is missing -- clock() should be hooked to a VBL interrupt - --------------------------------------------------------------------------------- - -a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) - -run the compiled binary like this: - -> mednafen -force_module pce <yourprogram.pce> - -joypad keys are mapped like this: - -w/s/a/d up/down/left/right -numpad 2 (?) button -numpad 3 (?) button -enter (start) button - --------------------------------------------------------------------------------- -some useful resources on PCE coding: - -http://blog.blockos.org/?tag=pc-engine -http://pcedev.blockos.org/viewforum.php?f=5 -http://www.romhacking.net/?page=documents&category=&platform=4&game=&author=&perpage=20&level=&title=&desc=&docsearch=Go -http://archaicpixels.com/Main_Page - -http://www.magicengine.com/mkit/doc.html - -https://github.com/uli/huc -http://www.zeograd.com/parse.php?src=hucf From 1e2d9f1796ba024a6c123b9fa5611dd48047798b Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 19 Jul 2015 13:36:27 +0200 Subject: [PATCH 18/28] fixed hline/vline --- asminc/pce.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 851b2f32a..4680ba826 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -16,8 +16,8 @@ tickcount = $39 ;4 screenrows = (224/8) charsperline = 61 -CH_HLINE = 7 -CH_VLINE = 7 +CH_HLINE = 1 +CH_VLINE = 2 ; huc6270 - Video Display Controller (vdc) From 313d2dd2104dd6f905ca3745fe1b9ea8e1259715 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 19 Jul 2015 18:06:16 +0200 Subject: [PATCH 19/28] added missing chline, cvline --- libsrc/pce/chline.s | 32 ++++++++++++++++++++++++++++++++ libsrc/pce/cvline.s | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 libsrc/pce/chline.s create mode 100644 libsrc/pce/cvline.s diff --git a/libsrc/pce/chline.s b/libsrc/pce/chline.s new file mode 100644 index 000000000..8bf8f1626 --- /dev/null +++ b/libsrc/pce/chline.s @@ -0,0 +1,32 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export _chlinexy, _chline + .import popa, _gotoxy, cputdirect + .importzp tmp1 + + .include "pce.inc" + +_chlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length + +_chline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #CH_HLINE ; Horizontal line, screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts + + + + diff --git a/libsrc/pce/cvline.s b/libsrc/pce/cvline.s new file mode 100644 index 000000000..abd74a5c7 --- /dev/null +++ b/libsrc/pce/cvline.s @@ -0,0 +1,32 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + + .export _cvlinexy, _cvline + .import popa, _gotoxy, putchar, newline + .importzp tmp1 + + .include "pce.inc" + +_cvlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cvline + +_cvline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #CH_VLINE ; Vertical bar + jsr putchar ; Write, no cursor advance + jsr newline ; Advance cursor to next line + dec tmp1 + bne L1 +L9: rts + + + From 4afcfb34982fbd3ed817fb29997c14b799a21ed2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 20 Jul 2015 16:03:03 +0200 Subject: [PATCH 20/28] fixed hello.c for pce --- samples/hello.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/hello.c b/samples/hello.c index 749a9d859..78c28af89 100644 --- a/samples/hello.c +++ b/samples/hello.c @@ -68,7 +68,7 @@ int main (void) gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); cprintf ("%s", Text); -#if defined(__NES__) +#if defined(__NES__) || defined(__PCE__) /* Wait for the user to press a button */ joy_install (joy_static_stddrv); From 57b8af1adc21f5c9215559af16f134957743baf6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 29 Aug 2015 15:58:57 +0200 Subject: [PATCH 21/28] style fixes --- README.md | 3 + asminc/pce.inc | 82 +++++------ include/pce.h | 30 ++-- libsrc/pce/_scrsize.s | 16 +- libsrc/pce/clock.s | 35 +++-- libsrc/pce/clrscr.s | 38 ++--- libsrc/pce/color.s | 83 +++++------ libsrc/pce/conio.s | 174 +++++++++++----------- libsrc/pce/cputc.s | 107 +++++++------- libsrc/pce/crt0.s | 276 ++++++++++++++++++----------------- libsrc/pce/gotoxy.s | 18 +-- libsrc/pce/joy/pce-stdjoy.s | 114 ++++++++------- libsrc/pce/joy_stat_stddrv.s | 6 +- libsrc/pce/joy_stddrv.s | 2 +- libsrc/pce/kplot.s | 43 +++--- libsrc/pce/psg.s | 44 +++--- libsrc/pce/revers.s | 32 ++-- libsrc/pce/vce.s | 29 ++-- libsrc/pce/vdc.s | 51 +++---- libsrc/pce/vga.inc | 257 ++++++++++++++++---------------- libsrc/pce/waitvblank.s | 10 +- testcode/lib/pce/conio.c | 198 ++++++++++++------------- 22 files changed, 830 insertions(+), 818 deletions(-) diff --git a/README.md b/README.md index 660798128..c93a6f920 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![build status](http://travis-ci.org/cc65/cc65.png)](http://travis-ci.org/cc65/cc65/builds) +Binary snapshot for [Windows](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) + cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several other tools. @@ -23,6 +25,7 @@ including - the Atari 8 bit machines. - the Atari 5200 console. - GEOS for the C64, C128 and Apple //e. +- the NEC PC-Engine - the Nintendo Entertainment System (NES) console. - the Supervision console. - the Oric Atmos. diff --git a/asminc/pce.inc b/asminc/pce.inc index 4680ba826..2d2843143 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -2,44 +2,44 @@ ; PCE definitions. By Groepaz/Hitmem. ; -;; FIXME: optimize zeropage usage +; FIXME: optimize zeropage usage +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 ;2 +CRAM_PTR = $34 ;2 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR = $38 +tickcount = $39 ;4 -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 ;2 -CRAM_PTR = $34 ;2 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR = $38 -tickcount = $39 ;4 +; FIXME: screen dimensions my change according to selected video mode +screenrows = (224/8) +charsperline = 61 -screenrows = (224/8) -charsperline = 61 - -CH_HLINE = 1 -CH_VLINE = 2 +CH_HLINE = 1 +CH_VLINE = 2 ; huc6270 - Video Display Controller (vdc) -VDC_MAWR = 0 ; Memory Address Write Register -VDC_MARR = 1 ; Memory Address Read Register -VDC_VWR = 2 ; VRAM Write Register -VDC_VRR = 3 ; VRAM Read Register -VDC_CR = 4 ; Control Register -VDC_RCR = 5 ; Raster Counter Register -VDC_BXR = 6 ; Background X-Scroll Register -VDC_BYR = 7 ; Background Y-Scroll Register -VDC_MWR = 8 ; Memory-access Width Register -VDC_HSR = 9 ; Horizontal Sync Register (?) -VDC_HDR =10 ; Horizontal Display Register (?) -VDC_VPR =11 ; (unknown) -VDC_VDW =12 ; (unknown use) -VDC_VCR =13 ; (unknown use) -VDC_DCR =14 ; (DMA) Control Register -VDC_SOUR =15 ; (DMA) Source Register -VDC_DESR =16 ; (DMA) Destination Register -VDC_LENR =17 ; (DMA) Length Register -VDC_SATB =18 ; Sprite Attribute Table +VDC_MAWR = 0 ; Memory Address Write Register +VDC_MARR = 1 ; Memory Address Read Register +VDC_VWR = 2 ; VRAM Write Register +VDC_VRR = 3 ; VRAM Read Register +VDC_CR = 4 ; Control Register +VDC_RCR = 5 ; Raster Counter Register +VDC_BXR = 6 ; Background X-Scroll Register +VDC_BYR = 7 ; Background Y-Scroll Register +VDC_MWR = 8 ; Memory-access Width Register +VDC_HSR = 9 ; Horizontal Sync Register (?) +VDC_HDR = 10 ; Horizontal Display Register (?) +VDC_VPR = 11 ; (unknown) +VDC_VDW = 12 ; (unknown use) +VDC_VCR = 13 ; (unknown use) +VDC_DCR = 14 ; (DMA) Control Register +VDC_SOUR = 15 ; (DMA) Source Register +VDC_DESR = 16 ; (DMA) Destination Register +VDC_LENR = 17 ; (DMA) Length Register +VDC_SATB = 18 ; Sprite Attribute Table ; VDC port ; Note: absolute addressing mode must be used when writing to this port @@ -54,21 +54,21 @@ VDC_DATA_HI = $0003 ; bitmap of the palette data is this: 0000000gggrrrbbb. ; You can read and write the DAC-registers. -VCE = $0400 ; base +VCE = $0400 ; base -VCE_CTRL = $0400 ; write$00 to reset -VCE_ADDR_LO = $0402 ; LSB of byte offset into palette -VCE_ADDR_HI = $0403 ; MSB of byte offset into palette -VCE_DATA_LO = $0404 ; LSB of 16-bit palette data -VCE_DATA_HI = $0405 ; MSB of 16-bit palette data +VCE_CTRL = $0400 ; write$00 to reset +VCE_ADDR_LO = $0402 ; LSB of byte offset into palette +VCE_ADDR_HI = $0403 ; MSB of byte offset into palette +VCE_DATA_LO = $0404 ; LSB of 16-bit palette data +VCE_DATA_HI = $0405 ; MSB of 16-bit palette data ; programmable sound generator (PSG) -PSG = $0800 ; base +PSG = $0800 ; base ; timer -TIMER = $0c00 ; base +TIMER = $0c00 ; base TIMER_COUNT = $0c00 TIMER_CTRL = $0c01 diff --git a/include/pce.h b/include/pce.h index 6f18ba501..7700654c8 100644 --- a/include/pce.h +++ b/include/pce.h @@ -36,20 +36,20 @@ # error This module may only be used when compiling for the PCE! #endif -#define CH_HLINE 1 -#define CH_VLINE 2 -#define CH_CROSS 3 -#define CH_ULCORNER 4 -#define CH_URCORNER 5 -#define CH_LLCORNER 6 -#define CH_LRCORNER 7 -#define CH_TTEE 8 -#define CH_BTEE 9 -#define CH_LTEE 10 -#define CH_RTEE 11 +#define CH_HLINE 1 +#define CH_VLINE 2 +#define CH_CROSS 3 +#define CH_ULCORNER 4 +#define CH_URCORNER 5 +#define CH_LLCORNER 6 +#define CH_LRCORNER 7 +#define CH_TTEE 8 +#define CH_BTEE 9 +#define CH_LTEE 10 +#define CH_RTEE 11 -#define CH_ENTER 13 -#define CH_PI 18 +#define CH_ENTER 13 +#define CH_PI 18 /* Color defines (CBM compatible, for conio) */ #define COLOR_BLACK 0x00 @@ -77,7 +77,7 @@ #define DYN_DRV 0 /* The addresses of the static drivers */ -extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ +extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_FIRE_B 5 #define JOY_SELECT 6 @@ -87,7 +87,7 @@ void waitvblank (void); /* Wait for the vertical blanking */ /* NOTE: all PCE are NTSC */ -#define get_tv() TV_NTSC +#define get_tv() TV_NTSC /* Return the video mode the machine is using. */ /* End of pce.h */ diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/_scrsize.s index 8dab2cf7b..038622a6f 100644 --- a/libsrc/pce/_scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -1,18 +1,18 @@ ; ; Screen size variables ; - .include "pce.inc" + .include "pce.inc" - .export screensize + .export screensize screensize: - ldx xsize - ldy ysize - rts + ldx xsize + ldy ysize + rts ; FIXME: changing the video mode allows for different screen sizes .rodata - .export xsize, ysize + .export xsize, ysize -xsize: .byte charsperline -ysize: .byte screenrows +xsize: .byte charsperline +ysize: .byte screenrows diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 5d0aa78f4..6b14232fe 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -2,30 +2,29 @@ ; clock_t clock (void); ; - .include "pce.inc" + .include "pce.inc" - .export _clock - .importzp sreg -;; .importzp tickcount + .export _clock + .importzp sreg .proc _clock - lda tickcount+3 - sta sreg+1 - lda tickcount+2 - sta sreg - ldx tickcount+1 - lda tickcount - rts + lda tickcount+3 + sta sreg+1 + lda tickcount+2 + sta sreg + ldx tickcount+1 + lda tickcount + rts .endproc - .constructor initclock, 24 + .constructor initclock, 24 initclock: - lda #0 - ldx #3 -@lp: sta tickcount,x - dex - bpl @lp - rts \ No newline at end of file + lda #0 + ldx #3 +@lp: sta tickcount,x + dex + bpl @lp + rts diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 9279f1e25..eae2b27a2 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,30 +1,32 @@ - .include "pce.inc" + .include "pce.inc" - .export _clrscr + .export _clrscr _clrscr: - st0 #VDC_MAWR - st1 #<$0000 - st2 #>$0000 + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 - st0 #VDC_VWR - ldy #$40 -rowloop: ldx #$80 -colloop: lda #' ' - sta a:VDC_DATA_LO - lda #$02 - sta a:VDC_DATA_HI + st0 #VDC_VWR + ldy #$40 +rowloop: + ldx #$80 +colloop: + lda #' ' + sta a:VDC_DATA_LO + lda #$02 + sta a:VDC_DATA_HI - dex - bne colloop - dey - bne rowloop + dex + bne colloop + dey + bne rowloop - rts + rts ;------------------------------------------------------------------------------- ; force the init constructor to be imported .import initconio -conio_init = initconio +conio_init = initconio diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 03d93b186..36c85b6b5 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -5,59 +5,60 @@ ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor, _bordercolor - .include "pce.inc" + .include "pce.inc" _textcolor: - ldx CHARCOLOR ; get old value - sta CHARCOLOR ; set new value - txa - rts + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts _bgcolor: - ldx BGCOLOR ; get old value - sta BGCOLOR ; set new value - asl a - tay + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay - stz VCE_ADDR_LO - stz VCE_ADDR_HI - lda colors,y - sta VCE_DATA_LO - lda colors+1,y - sta VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI - txa - rts + txa + rts _bordercolor: - lda #0 - txa - rts + lda #0 + txa + rts - .export colors + .export colors -colors: ; G R B - .word ((0<<6)+(0<<3)+(0)) ; 0 black - .word ((7<<6)+(7<<3)+(7)) ; 1 white - .word ((0<<6)+(7<<3)+(0)) ; 2 red - .word ((7<<6)+(0<<3)+(7)) ; 3 cyan - .word ((0<<6)+(5<<3)+(7)) ; 4 violett - .word ((7<<6)+(0<<3)+(0)) ; 5 green - .word ((0<<6)+(0<<3)+(7)) ; 6 blue - .word ((7<<6)+(7<<3)+(0)) ; 7 yellow - .word ((5<<6)+(7<<3)+(0)) ; 8 orange - .word ((3<<6)+(4<<3)+(3)) ; 9 brown - .word ((4<<6)+(7<<3)+(4)) ; a light red - .word ((3<<6)+(3<<3)+(3)) ; b dark grey - .word ((4<<6)+(4<<3)+(4)) ; c middle grey - .word ((7<<6)+(4<<3)+(4)) ; d light green - .word ((4<<6)+(4<<3)+(7)) ; e light blue - .word ((6<<6)+(6<<3)+(6)) ; f light gray +colors: + ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 4fb3b1394..b9333e1fa 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,121 +1,123 @@ - .include "pce.inc" + .include "pce.inc" - .import vce_init - .import psg_init - .import vdc_init + .import vce_init + .import psg_init + .import vdc_init - .constructor initconio, 24 + .constructor initconio, 24 + + .macpack longbranch - .macpack longbranch initconio: -;; jsr vdc_init - jsr vce_init - jsr psg_init - jsr conio_init - jsr set_palette + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette - st0 #VDC_RCR - st1 #<$0088 - st2 #>$0088 - rts + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts - .import colors + .import colors set_palette: - stz VCE_ADDR_LO - stz VCE_ADDR_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI - ldx #0 + ldx #0 @lp: - ldy #16 + ldy #16 @lp1: - lda colors,x - sta VCE_DATA_LO - lda colors+1,x - sta VCE_DATA_HI - dey - bne @lp1 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + dey + bne @lp1 - inx - inx - cpx #16*2 - jne @lp + inx + inx + cpx #16*2 + jne @lp - stz VCE_ADDR_LO - stz VCE_ADDR_HI - stz VCE_DATA_LO - stz VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI - rts + rts ;---------------------------------------------------------------------------- ; ;---------------------------------------------------------------------------- - .importzp ptr1, tmp1 + .importzp ptr1, tmp1 conio_init: - ; Load font - st0 #VDC_MAWR - st1 #<$2000 - st2 #>$2000 + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 - ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + ; ptr to font data + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - lda #0 - sta tmp1 - jsr copy + lda #0 + sta tmp1 + jsr copy - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - lda #$ff - sta tmp1 - jsr copy + lda #$ff + sta tmp1 + jsr copy - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR - rts + rts copy: - ldy #$80 ; 128 chars -charloop: ldx #$08 ; 8 bytes/char + ldy #$80 ; 128 chars +charloop: + ldx #$08 ; 8 bytes/char lineloop: - lda (ptr1) - eor tmp1 - sta a:VDC_DATA_LO ; bitplane 0 - stz a:VDC_DATA_HI ; bitplane 1 + lda (ptr1) + eor tmp1 + sta a:VDC_DATA_LO ; bitplane 0 + stz a:VDC_DATA_HI ; bitplane 1 - clc ; increment font pointer - lda ptr1 - adc #$01 - sta ptr1 - lda ptr1+1 - adc #$00 - sta ptr1+1 - dex - bne lineloop ; next bitplane 0 byte - ldx #$08 ; fill bitplane 2/3 with 0 -fillloop: st1 #$00 - st2 #$00 - dex - bne fillloop ; next byte - dey - bne charloop ; next character + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 +fillloop: + st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character - rts + rts - .rodata + .rodata font: - .include "vga.inc" + .include "vga.inc" diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index 918f39e29..d31e13769 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -3,97 +3,96 @@ ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - .import PLOT - .import xsize + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + .import xsize - .importzp tmp3,tmp4 + .importzp tmp3,tmp4 + + .include "pce.inc" - .include "pce.inc" _cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C ; Plot a character - also used as internal function -_cputc: cmp #$0d ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers -L1: cmp #$0a ; LF? - beq newline ; Recalculate pointers +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: - jsr putchar ; Write the character to the screen + jsr putchar ; Write the character to the screen ; Advance cursor position advance: - ldy CURS_X - iny - cpy xsize - bne L3 - jsr newline ; new line - ldy #0 ; + cr -L3: sty CURS_X - jmp plot + ldy CURS_X + iny + cpy xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot newline: - inc CURS_Y + inc CURS_Y ; Set cursor position, calculate RAM pointers -plot: ldy CURS_X - ldx CURS_Y - clc - jmp PLOT ; Set the new cursor - - +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor ; Write one character to the screen without doing anything else, return X ; position in Y putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit - tax + tax - st0 #VDC_MAWR ; Memory Adress Write + st0 #VDC_MAWR ; Memory Adress Write - lda SCREEN_PTR - sta a:VDC_DATA_LO + lda SCREEN_PTR + sta a:VDC_DATA_LO - lda SCREEN_PTR+1 - sta a:VDC_DATA_HI + lda SCREEN_PTR + 1 + sta a:VDC_DATA_HI - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - txa - sta a:VDC_DATA_LO ; character + txa + sta a:VDC_DATA_LO ; character - lda CHARCOLOR + lda CHARCOLOR - asl a - asl a - asl a - asl a + asl a + asl a + asl a + asl a - ora #$02 - sta a:VDC_DATA_HI + ora #$02 + sta a:VDC_DATA_HI - rts + rts ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 2b8455a59..f89119c46 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -7,153 +7,155 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .export __STARTUP__ : absolute = 1 ; Mark as startup + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup - .import initlib, donelib - .import push0, _main, zerobss - .import initheap - .import tmp1,tmp2,tmp3 + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 ; 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__ + .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__ - .include "pce.inc" + .include "pce.inc" - .importzp sp - .importzp ptr1,ptr2 + .importzp sp + .importzp ptr1,ptr2 ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. - .segment "STARTUP" + .segment "STARTUP" start: - ; setup the CPU and System-IRQ + ; setup the CPU and System-IRQ - ; Initialize CPU + ; Initialize CPU - sei - nop - csh ; set high speed CPU mode - nop - cld - nop + sei + nop + csh ; set high speed CPU mode + nop + cld + nop - ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) - txs + ; Setup stack and memory mapping + 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 - lda #$F8 - 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 - ;lda #4 - ;tam #%01000000 ; C000-DFFF Page 5 - ;lda #0 - ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 + ; at startup all MPRs are set to 0, so init them + lda #$ff + tam #%00000001 ; 0000-1FFF = Hardware page + lda #$F8 + tam #%00000010 ; 2000-3FFF = Work RAM - ; Clear work RAM (2000-3FFF) - stz <$00 - tii $2000, $2001, $1FFF + ; FIXME: setup a larger block of memory to use with C-code + ;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 + ;lda #4 + ;tam #%01000000 ; C000-DFFF Page 5 + ;lda #0 + ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 - ; Initialize hardware - stz TIMER_COUNT ; Timer off - lda #$07 - sta IRQ_MASK ; Interrupts off - stz IRQ_STATUS ; Acknowledge timer + ; Clear work RAM (2000-3FFF) + stz <$00 + tii $2000, $2001, $1FFF - ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ - .import vdc_init - jsr vdc_init + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer - ; Turn on background and VD interrupt/IRQ1 - lda #$05 - sta IRQ_MASK ; IRQ1=on + ; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ + .import vdc_init + jsr vdc_init - ; Clear the BSS data - jsr zerobss + ; Turn on background and VD interrupt/IRQ1 + lda #$05 + sta IRQ_MASK ; IRQ1=on - ; Copy the .data segment to RAM - lda #<(__DATA_LOAD__) - sta ptr1 - lda #>(__DATA_LOAD__) - sta ptr1+1 - lda #<(__DATA_RUN__) - sta ptr2 - lda #>(__DATA_RUN__) - sta ptr2+1 + ; Clear the BSS data + jsr zerobss - ldx #>(__DATA_SIZE__) + ; Copy the .data segment to RAM + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 + + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 - dex - bne @l2 + dex + bne @l2 - ; copy remaining bytes + ; copy remaining bytes @s1: - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 - ; setup the stack - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 + ; setup the stack + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp + 1 - ; Call module constructors - jsr initlib + ; Call module constructors + jsr initlib - cli ; allow IRQ only after constructors have run + cli ; allow IRQ only after constructors have run - ; Pass an empty command line - jsr push0 ; argc - jsr push0 ; argv + ; Pass an empty command line + jsr push0 ; argc + jsr push0 ; argv - ldy #4 ; Argument size - jsr _main ; call the users code + ldy #4 ; Argument size + jsr _main ; call the users code - ; Call module destructors. This is also the _exit entry. + ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors - ; reset the PCEngine (start over) - jmp start + ; reset the PCEngine (start over) + jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt @@ -161,45 +163,45 @@ _exit: ; ------------------------------------------------------------------------ _irq1: - pha - phx - phy + pha + phx + phy - - inc tickcount - bne @s1 - inc tickcount+1 - bne @s1 - inc tickcount+2 - bne @s1 - inc tickcount+3 + ; increment the system tick counter + inc tickcount + bne @s1 + inc tickcount + 1 + bne @s1 + inc tickcount + 2 + bne @s1 + inc tickcount + 3 @s1: - ; Acknowlege interrupt - lda a:VDC_CTRL + ; Acknowlege interrupt + lda a:VDC_CTRL - ply - plx - pla - rti + ply + plx + pla + rti _irq2: - rti + rti _nmi: - rti + rti _timer: - stz IRQ_STATUS - rti + stz IRQ_STATUS + rti - .export initmainargs + .export initmainargs initmainargs: - rts + rts ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ - .segment "VECTORS" + .segment "VECTORS" - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer - .word _nmi ; $fffc NMI - .word start ; $fffe reset + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index c6b937177..c7cda83f3 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -2,20 +2,20 @@ ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - .import popa, plot + .export _gotoxy + .import popa, plot - .include "pce.inc" + .include "pce.inc" _gotoxy: - sta CURS_Y ; Set Y - jsr popa ; Get X - sta CURS_X ; Set X - jmp plot ; Set the cursor position + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 592793250..746929dd2 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -5,6 +5,7 @@ .include "joy-kernel.inc" .include "joy-error.inc" + .include "pce.inc" .macpack module @@ -58,10 +59,10 @@ JOY_COUNT = 4 ; Number of joysticks we support ; INSTALL: - lda #<JOY_ERR_OK - ldx #>JOY_ERR_OK + lda #<JOY_ERR_OK + ldx #>JOY_ERR_OK -; rts ; Run into DEINSTALL instead +; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ ; DEINSTALL routine. Is called before the driver is removed from memory. @@ -69,7 +70,7 @@ INSTALL: ; UNINSTALL: - rts + rts ; ------------------------------------------------------------------------ @@ -78,9 +79,9 @@ UNINSTALL: ;unsigned char __fastcall__ joy_count (void); COUNT: - lda #<JOY_COUNT - ldx #>JOY_COUNT - rts + lda #<JOY_COUNT + ldx #>JOY_COUNT + rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. @@ -88,70 +89,71 @@ COUNT: ;unsigned char __fastcall__ joy_read (unsigned char joystick); READJOY: - pha - jsr read_joy - pla - tax ; Joystick number into X + pha + jsr read_joy + pla + tax ; Joystick number into X - ; return value from buffer + ; return value from buffer joy1: - lda padbuffer,x - ldx #0 - rts + lda padbuffer,x + ldx #0 + rts read_joy: - ; reset multitap counter - lda #$01 - sta $1000 - pha - pla - nop - nop + ; reset multitap counter + lda #$01 + sta JOY_CTRL + pha + pla + nop + nop - lda #$03 - sta $1000 - pha - pla - nop - nop + lda #$03 + sta JOY_CTRL + pha + pla + nop + nop - cly + cly nextpad: - lda #$01 - sta $1000 ; sel = 1 - pha - pla - nop - nop + lda #$01 + sta JOY_CTRL ; sel = 1 + pha + pla + nop ; some delay is required + nop - lda $1000 - asl a - asl a - asl a - asl a - sta padbuffer, y ; store new value + lda JOY_CTRL + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value - stz $1000 - pha - pla - nop - nop + stz JOY_CTRL + pha + pla - lda $1000 - and #$0F - ora padbuffer, y ; second half of new value + nop ; some delay is required + nop - eor #$FF - sta padbuffer, y ; store new value + lda JOY_CTRL + and #$0F + ora padbuffer, y ; second half of new value - iny - cpy #$05 - bcc nextpad - rts + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts .bss padbuffer: - .res 4 + .res 4 diff --git a/libsrc/pce/joy_stat_stddrv.s b/libsrc/pce/joy_stat_stddrv.s index 3972569ed..2424c456b 100644 --- a/libsrc/pce/joy_stat_stddrv.s +++ b/libsrc/pce/joy_stat_stddrv.s @@ -6,9 +6,9 @@ ; const void joy_static_stddrv[]; ; - .export _joy_static_stddrv - .import _pce_stdjoy_joy + .export _joy_static_stddrv + .import _pce_stdjoy_joy .rodata -_joy_static_stddrv := _pce_stdjoy_joy +_joy_static_stddrv := _pce_stdjoy_joy diff --git a/libsrc/pce/joy_stddrv.s b/libsrc/pce/joy_stddrv.s index e0ed6957e..ba397409a 100644 --- a/libsrc/pce/joy_stddrv.s +++ b/libsrc/pce/joy_stddrv.s @@ -6,7 +6,7 @@ ; const char joy_stddrv[]; ; - .export _joy_stddrv + .export _joy_stddrv .rodata diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index eb4e79e04..b580f8473 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -1,37 +1,36 @@ - .export PLOT + .export PLOT - .include "pce.inc" + .include "pce.inc" PLOT: - bcs @getpos + bcs @getpos - tya - clc - adc _plotlo,x - sta SCREEN_PTR + tya + clc + adc _plotlo,x + sta SCREEN_PTR - lda _plothi,x - adc #0 - sta SCREEN_PTR+1 + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 @getpos: - ldx CURS_Y - ldy CURS_X - rts + ldx CURS_Y + ldy CURS_X + rts _plotlo: - .repeat screenrows,line - .byte <($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat _plothi: - .repeat screenrows,line - .byte >($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio - + .import initconio +conio_init = initconio diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 431f58834..645c02615 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,29 +1,29 @@ - .include "pce.inc" + .include "pce.inc" - .export psg_init + .export psg_init psg_init: - clx - stx $0800 ; Select channel + clx + stx $0800 ; Select channel psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control - cly -psg_clear_waveform: stz $0806 ; Clear waveform byte - iny - cpy #$20 - bne psg_clear_waveform - - inx - cpx #$06 - bne psg_clear_loop - rts + cly +psg_clear_waveform: + stz $0806 ; Clear waveform byte + iny + cpy #$20 + bne psg_clear_waveform + inx + cpx #$06 + bne psg_clear_loop + rts diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index 061023d09..1773de2b0 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,27 +1,27 @@ - .include "pce.inc" + .include "pce.inc" - .export _revers + .export _revers .proc _revers - ldx #$00 ; Assume revers off - tay ; Test onoff - beq L1 ; Jump if off - ldx #$80 ; Load on value - ldy #$00 ; Assume old value is zero -L1: lda RVS ; Load old value - stx RVS ; Set new value - beq L2 ; Jump if old value zero - iny ; Make old value = 1 -L2: ldx #$00 ; Load high byte of result - tya ; Load low byte, set CC - rts + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts .endproc ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 461fd1e75..3c19fd55b 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,17 +1,20 @@ - .include "pce.inc" + .include "pce.inc" - .export vce_init + .export vce_init vce_init: - stz VCE_ADDR_LO ; - stz VCE_ADDR_HI ; Set CTA to zero - ldy #$01 -vce_clear_bank: ldx #$00 -vce_clear_color: stz VCE_DATA_LO ; Clear color (LSB) - stz VCE_DATA_HI ; Clear color (MSB) - dex - bne vce_clear_color - dey - bne vce_clear_bank - rts + ; Set CTA to zero + stz VCE_ADDR_LO + stz VCE_ADDR_HI + ldy #$01 +vce_clear_bank: + ldx #$00 +vce_clear_color: + stz VCE_DATA_LO ; Clear color (LSB) + stz VCE_DATA_HI ; Clear color (MSB) + dex + bne vce_clear_color + dey + bne vce_clear_bank + rts diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index 0f42fe1b0..878c79321 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,40 +1,41 @@ - .include "pce.inc" + .include "pce.inc" -HIRES = 1 +; FIXME: implement selection of different video modes at runtime +HIRES = 1 - .export vdc_init + .export vdc_init vdc_init: - lda a:VDC_CTRL + lda a:VDC_CTRL - VREG $00, $0000 ; MAWR - VREG $01, $0000 ; MARR - VREG $05, $0000 ; CR - VREG $06, $0000 ; RCR - VREG $07, $0000 ; BXR - VREG $08, $0000 ; BYR - VREG $09, $0070 ; MAWR - VREG $0C, $1702 ; CRTC - VSR - VREG $0D, $00DF ; CRTC - VDS - VREG $0E, $000C ; CRTC - VDE - VREG $0F, $0000 ; DCR + VREG $00, $0000 ; MAWR + VREG $01, $0000 ; MARR + VREG $05, $0000 ; CR + VREG $06, $0000 ; RCR + VREG $07, $0000 ; BXR + VREG $08, $0000 ; BYR + VREG $09, $0070 ; MAWR + VREG $0C, $1702 ; CRTC - VSR + VREG $0D, $00DF ; CRTC - VDS + VREG $0E, $000C ; CRTC - VDE + VREG $0F, $0000 ; DCR .if HIRES - VREG $0A, $0C02 ; CRTC - HSR - VREG $0B, $043C ; CRTC - HDS - lda #$06 - sta VCE_CTRL + VREG $0A, $0C02 ; CRTC - HSR + VREG $0B, $043C ; CRTC - HDS + lda #$06 + sta VCE_CTRL .else - VREG $0A, $0202 ; CRTC - HSR - VREG $0B, $041F ; CRTC - HDS - lda #$04 - sta VCE_CTRL + VREG $0A, $0202 ; CRTC - HSR + VREG $0B, $041F ; CRTC - HDS + lda #$04 + sta VCE_CTRL .endif - lda a:VDC_CTRL - rts + lda a:VDC_CTRL + rts diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index b5c4b27fd..9317d6ce4 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -1,8 +1,8 @@ ; VGA charset for the PC-Engine conio implementation - .byte $00, $00, $00, $00, $00, $00, $00, $00 - ;;.byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte %00000000 .byte %00000000 .byte %00000000 @@ -11,7 +11,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte %00010000 .byte %00010000 .byte %00010000 @@ -20,7 +20,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -29,7 +29,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte %00000000 .byte %00000000 .byte %00000000 @@ -38,7 +38,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte %00000000 .byte %00000000 .byte %00000000 @@ -47,7 +47,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte %00010000 .byte %00010000 .byte %00010000 @@ -56,7 +56,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -65,7 +65,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte %00000000 .byte %00000000 .byte %00000000 @@ -74,7 +74,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -83,7 +83,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte %00010000 .byte %00010000 .byte %00010000 @@ -92,7 +92,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -101,119 +101,120 @@ .byte %00010000 .byte %00010000 .byte %00010000 - .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 - .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 - .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 - .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 - .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 - .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 - .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 - .byte $66, $66, $66, $66, $66, $00, $66, $00 - .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 - .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 - .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 - .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF - .byte $18, $3C, $7E, $18, $18, $18, $18, $00 - .byte $18, $18, $18, $18, $7E, $3C, $18, $00 - .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 - .byte $00, $30, $60, $FE, $60, $30, $00, $00 - .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 - .byte $00, $24, $66, $FF, $66, $24, $00, $00 - .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 - .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 - .byte $00, $00, $00, $00, $00, $00, $00, $00 - .byte $30, $78, $78, $78, $30, $00, $30, $00 - .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 - .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 - .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 - .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 - .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 - .byte $60, $60, $C0, $00, $00, $00, $00, $00 - .byte $18, $30, $60, $60, $60, $30, $18, $00 - .byte $60, $30, $18, $18, $18, $30, $60, $00 - .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 - .byte $00, $30, $30, $FC, $30, $30, $00, $00 - .byte $00, $00, $00, $00, $00, $30, $30, $60 - .byte $00, $00, $00, $FC, $00, $00, $00, $00 - .byte $00, $00, $00, $00, $00, $30, $30, $00 - .byte $06, $0C, $18, $30, $60, $C0, $80, $00 - .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 - .byte $30, $70, $30, $30, $30, $30, $FC, $00 - .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 - .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 - .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 - .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 - .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 - .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 - .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 - .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 - .byte $00, $30, $30, $00, $00, $30, $30, $00 - .byte $00, $30, $30, $00, $00, $30, $30, $60 - .byte $18, $30, $60, $C0, $60, $30, $18, $00 - .byte $00, $00, $FC, $00, $00, $FC, $00, $00 - .byte $60, $30, $18, $0C, $18, $30, $60, $00 - .byte $78, $CC, $0C, $18, $30, $00, $30, $00 - .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 - .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 - .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 - .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 - .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 - .byte $7E, $60, $60, $78, $60, $60, $7E, $00 - .byte $7E, $60, $60, $78, $60, $60, $60, $00 - .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 - .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 - .byte $78, $30, $30, $30, $30, $30, $78, $00 - .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 - .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 - .byte $60, $60, $60, $60, $60, $60, $7E, $00 - .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 - .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 - .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 - .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 - .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 - .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 - .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 - .byte $FC, $30, $30, $30, $30, $30, $30, $00 - .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 - .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 - .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 - .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 - .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 - .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 - .byte $78, $60, $60, $60, $60, $60, $78, $00 - .byte $C0, $60, $30, $18, $0C, $06, $02, $00 - .byte $78, $18, $18, $18, $18, $18, $78, $00 - .byte $10, $38, $6C, $C6, $00, $00, $00, $00 - .byte $00, $00, $00, $00, $00, $00, $00, $FF - .byte $30, $30, $18, $00, $00, $00, $00, $00 - .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 - .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 - .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 - .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 - .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 - .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 - .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 - .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 - .byte $30, $00, $70, $30, $30, $30, $78, $00 - .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 - .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 - .byte $70, $30, $30, $30, $30, $30, $78, $00 - .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 - .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 - .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 - .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 - .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E - .byte $00, $00, $DC, $76, $66, $60, $F0, $00 - .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 - .byte $10, $30, $7C, $30, $30, $34, $18, $00 - .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 - .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 - .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 - .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 - .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 - .byte $00, $00, $FC, $98, $30, $64, $FC, $00 - .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 - .byte $18, $18, $18, $00, $18, $18, $18, $00 - .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 - .byte $76, $DC, $00, $00, $00, $00, $00, $00 - .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 + + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 + .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 + .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 + .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 + .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 + .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 + .byte $66, $66, $66, $66, $66, $00, $66, $00 + .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 + .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 + .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 + .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF + .byte $18, $3C, $7E, $18, $18, $18, $18, $00 + .byte $18, $18, $18, $18, $7E, $3C, $18, $00 + .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 + .byte $00, $30, $60, $FE, $60, $30, $00, $00 + .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 + .byte $00, $24, $66, $FF, $66, $24, $00, $00 + .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 + .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $30, $78, $78, $78, $30, $00, $30, $00 + .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 + .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 + .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 + .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 + .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 + .byte $60, $60, $C0, $00, $00, $00, $00, $00 + .byte $18, $30, $60, $60, $60, $30, $18, $00 + .byte $60, $30, $18, $18, $18, $30, $60, $00 + .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 + .byte $00, $30, $30, $FC, $30, $30, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $60 + .byte $00, $00, $00, $FC, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $00 + .byte $06, $0C, $18, $30, $60, $C0, $80, $00 + .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 + .byte $30, $70, $30, $30, $30, $30, $FC, $00 + .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 + .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 + .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 + .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 + .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 + .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 + .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 + .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $60 + .byte $18, $30, $60, $C0, $60, $30, $18, $00 + .byte $00, $00, $FC, $00, $00, $FC, $00, $00 + .byte $60, $30, $18, $0C, $18, $30, $60, $00 + .byte $78, $CC, $0C, $18, $30, $00, $30, $00 + .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 + .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 + .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 + .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 + .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 + .byte $7E, $60, $60, $78, $60, $60, $7E, $00 + .byte $7E, $60, $60, $78, $60, $60, $60, $00 + .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 + .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 + .byte $78, $30, $30, $30, $30, $30, $78, $00 + .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 + .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 + .byte $60, $60, $60, $60, $60, $60, $7E, $00 + .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 + .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 + .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 + .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 + .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 + .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 + .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 + .byte $FC, $30, $30, $30, $30, $30, $30, $00 + .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 + .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 + .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 + .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 + .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 + .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 + .byte $78, $60, $60, $60, $60, $60, $78, $00 + .byte $C0, $60, $30, $18, $0C, $06, $02, $00 + .byte $78, $18, $18, $18, $18, $18, $78, $00 + .byte $10, $38, $6C, $C6, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $FF + .byte $30, $30, $18, $00, $00, $00, $00, $00 + .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 + .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 + .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 + .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 + .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 + .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 + .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 + .byte $30, $00, $70, $30, $30, $30, $78, $00 + .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 + .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 + .byte $70, $30, $30, $30, $30, $30, $78, $00 + .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 + .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 + .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 + .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E + .byte $00, $00, $DC, $76, $66, $60, $F0, $00 + .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 + .byte $10, $30, $7C, $30, $30, $34, $18, $00 + .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 + .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 + .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 + .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 + .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 + .byte $00, $00, $FC, $98, $30, $64, $FC, $00 + .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 + .byte $18, $18, $18, $00, $18, $18, $18, $00 + .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 + .byte $76, $DC, $00, $00, $00, $00, $00, $00 + .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index 2ded2835e..b4e31f45a 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -2,17 +2,15 @@ ; void waitvblank (void); ; - .include "pce.inc" + .include "pce.inc" .export _waitvblank -;; .importzp tickcount .proc _waitvblank - lda tickcount -@lp: cmp tickcount - beq @lp + lda tickcount +@lp: cmp tickcount + beq @lp rts .endproc - diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index f5231dba6..44da30a2a 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -9,113 +9,113 @@ static int datavar = 10; void main(void) { - int stackvar = 42; - int i, j; - clock_t clk; - char *p; - unsigned char xsize, ysize, n; + int stackvar = 42; + int i, j; + clock_t clk; + char* p; + unsigned char xsize, ysize, n; - joy_install(&joy_static_stddrv); + joy_install(&joy_static_stddrv); - clrscr(); - screensize(&xsize, &ysize); + clrscr(); + screensize(&xsize, &ysize); - cputs("hello world"); - cputsxy(0, 2, "colors:" ); - for (i = 0; i < 16; ++i) { - textcolor(i); - cputc('X'); - } - textcolor(1); - - gotoxy(0,4); - cprintf("datavar: %02x\n\r", datavar); - cprintf("stackvar: %02x\n\r", stackvar); - - j = joy_count(); - gotoxy(0,10); - cprintf("Found %d Joysticks.", j); - - for (i = 0; i < 4; ++i) { - gotoxy(0, 17 + i); - p = malloc(16); - memcpy(p, "01234567890abcdef", 16); - cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, - p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] - ); - } - - gotoxy(0,ysize - 1); - for (i = 0; i < xsize; ++i) { - cputc('0' + i % 10); - } - - gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); - for (i = 0; i < xsize; ++i) { - cputc('0' + i % 10); - } - for (i = 0; i < (xsize * 5); ++i) { - cputc('#'); - } - gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); - for (i = 0; i < 256; ++i) { - if ((i != '\n') && (i != '\r')) { - cputc(i); + cputs("hello world"); + cputsxy(0, 2, "colors:" ); + for (i = 0; i < 16; ++i) { + textcolor(i); + cputc('X'); } - } + textcolor(1); - i = get_tv(); - gotoxy(30,0); - cputs("TV Mode: "); - switch(i) { - case TV_NTSC: - cputs("NTSC"); - break; - case TV_PAL: - cputs("PAL"); - break; - case TV_OTHER: - cputs("OTHER"); - break; - } - cprintf(" %dx%d", xsize, ysize); + gotoxy(0,4); + cprintf("datavar: %02x\n\r", datavar); + cprintf("stackvar: %02x\n\r", stackvar); - for(;;) { - gotoxy(13,4); - cprintf("%02x", datavar); - gotoxy(13,5); - cprintf("%02x", stackvar); - ++datavar; ++stackvar; + j = joy_count(); + gotoxy(0,10); + cprintf("Found %d Joysticks.", j); - gotoxy(0,8); - clk = clock(); - cprintf("clock: %08lx", clk); - - for (i = 0; i < 4; ++i) - { - gotoxy(0, 12 + i); - j = joy_read (i); - cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", - i, j, - (j & joy_masks[JOY_UP])? " up " : " ---- ", - (j & joy_masks[JOY_DOWN])? " down " : " ---- ", - (j & joy_masks[JOY_LEFT])? " left " : " ---- ", - (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", - (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", - (j & joy_masks[JOY_SELECT])? "select" : " ---- ", - (j & joy_masks[JOY_RUN])? " run " : " ---- "); + for (i = 0; i < 4; ++i) { + gotoxy(0, 17 + i); + p = malloc(16); + memcpy(p, "01234567890abcdef", 16); + cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], + p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] + ); } - gotoxy(xsize - 10, 3); - j = (n >> 5) & 1; - revers(j); - cputc(j ? 'R' : ' '); - cputs(" revers"); - revers(0); + gotoxy(0,ysize - 1); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } - waitvblank(); - ++n; - } - for(;;); + gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + for (i = 0; i < (xsize * 5); ++i) { + cputc('#'); + } + gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); + for (i = 0; i < 256; ++i) { + if ((i != '\n') && (i != '\r')) { + cputc(i); + } + } + + i = get_tv(); + gotoxy(30,0); + cputs("TV Mode: "); + switch(i) { + case TV_NTSC: + cputs("NTSC"); + break; + case TV_PAL: + cputs("PAL"); + break; + case TV_OTHER: + cputs("OTHER"); + break; + } + cprintf(" %dx%d", xsize, ysize); + + for(;;) { + gotoxy(13,4); + cprintf("%02x", datavar); + gotoxy(13,5); + cprintf("%02x", stackvar); + ++datavar; ++stackvar; + + gotoxy(0,8); + clk = clock(); + cprintf("clock: %08lx", clk); + + for (i = 0; i < 4; ++i) { + gotoxy(0, 12 + i); + j = joy_read (i); + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", + i, j, + (j & joy_masks[JOY_UP])? " up " : " ---- ", + (j & joy_masks[JOY_DOWN])? " down " : " ---- ", + (j & joy_masks[JOY_LEFT])? " left " : " ---- ", + (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", + (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", + (j & joy_masks[JOY_SELECT])? "select" : " ---- ", + (j & joy_masks[JOY_RUN])? " run " : " ---- "); + } + + gotoxy(xsize - 10, 3); + j = (n >> 5) & 1; + revers(j); + cputc(j ? 'R' : ' '); + cputs(" revers"); + revers(0); + + waitvblank(); + ++n; + } + for(;;); } From 01baf36fa841174ec9b6a7be30b489672cb0917e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 3 Sep 2015 13:09:18 +0200 Subject: [PATCH 22/28] fixed style issues --- doc/pce.sgml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/pce.sgml b/doc/pce.sgml index 74692ce16..ba59c31a7 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -78,7 +78,7 @@ Programs containing PCE specific code may use the <tt/pce.h/ header file. <itemize> <item>waitvblank</item> -<item>get_tv</item> (since all PCE systems are NTSC, this always returns TV_NTSC) +<item>get_tv (since all PCE systems are NTSC, this always returns TV_NTSC)</item> </itemize> @@ -111,12 +111,8 @@ The names in the parentheses denote the symbols to be used for static linking of <sect1>Graphics drivers<p> -<descrip> - No TGI graphics drivers are currently available for the PCE. -</descrip><p> - <sect1>Extended memory drivers<p> @@ -175,7 +171,7 @@ following functions (and a few others): <sect>Other hints<p> <itemize> -<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.sourceforge.net">) +<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.fobby.net/">) </itemize> some useful resources on PCE coding: From 9fe0c34fe6ea7aa7a6e5f6bb7fbca75c572c7c21 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 4 Sep 2015 13:38:17 +0200 Subject: [PATCH 23/28] updated --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c93a6f920..4a0a50bed 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [wiki](http://github.com/cc65/wiki/wiki) -[![build status](http://travis-ci.org/cc65/cc65.png)](http://travis-ci.org/cc65/cc65/builds) +[![build status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) Binary snapshot for [Windows](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) @@ -25,7 +25,7 @@ including - the Atari 8 bit machines. - the Atari 5200 console. - GEOS for the C64, C128 and Apple //e. -- the NEC PC-Engine +- the NEC PC-Engine (aka TurboGrafx-16). - the Nintendo Entertainment System (NES) console. - the Supervision console. - the Oric Atmos. From af2ba26c626735787b8513237397c371719f832c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 4 Sep 2015 14:14:17 +0200 Subject: [PATCH 24/28] fix gregs complaints :) --- asminc/pce.inc | 20 +++++++++++++++----- libsrc/pce/kplot.s | 2 ++ libsrc/pce/psg.s | 21 +++++++++++---------- testcode/lib/pce/Makefile | 3 ++- testcode/lib/pce/conio.c | 10 +++++----- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 2d2843143..9a77bcc4e 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -6,11 +6,10 @@ CURS_X = $30 CURS_Y = $31 SCREEN_PTR = $32 ;2 -CRAM_PTR = $34 ;2 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR = $38 -tickcount = $39 ;4 +CHARCOLOR = $34 +RVS = $35 +BGCOLOR = $36 +tickcount = $37 ;4 ; FIXME: screen dimensions my change according to selected video mode screenrows = (224/8) @@ -66,6 +65,17 @@ VCE_DATA_HI = $0405 ; MSB of 16-bit palette data PSG = $0800 ; base +PSG_CHAN_SELECT = $0800 +PSG_GLOBAL_PAN = $0801 +PSG_FREQ_LO = $0802 +PSG_FREQ_HI = $0803 +PSG_CHAN_CTRL = $0804 +PSG_CHAN_PAN = $0805 +PSG_CHAN_DATA = $0806 +PSG_NOISE = $0807 +PSG_LFO_FREQ = $0808 +PSG_LFO_CTRL = $0809 + ; timer TIMER = $0c00 ; base diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index b580f8473..24ae8fab7 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -19,6 +19,8 @@ PLOT: ldy CURS_X rts + .rodata + _plotlo: .repeat screenrows,line .byte <($0000+(line*$80)) diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 645c02615..17d26b941 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -5,20 +5,21 @@ psg_init: clx - stx $0800 ; Select channel + stz PSG_GLOBAL_PAN ; Clear global balance + psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stx PSG_CHAN_SELECT ; Select channel + stz PSG_FREQ_LO ; Clear frequency LSB + stz PSG_FREQ_HI ; Clear frequency MSB + stz PSG_CHAN_CTRL ; Clear volume + stz PSG_CHAN_PAN ; Clear balance + stz PSG_NOISE ; Clear noise control + stz PSG_LFO_FREQ ; Clear LFO frequency + stz PSG_LFO_CTRL ; Clear LFO control cly psg_clear_waveform: - stz $0806 ; Clear waveform byte + stz PSG_CHAN_DATA ; Clear waveform byte iny cpy #$20 bne psg_clear_waveform diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile index 364074180..1fee199fd 100644 --- a/testcode/lib/pce/Makefile +++ b/testcode/lib/pce/Makefile @@ -2,10 +2,11 @@ all: conio.pce conio.pce: conio.c - ../../../bin/cl65 -t pce conio.c ../../../joy/pce-stdjoy.joy --mapfile conio.map -o conio.pce + ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce clean: $(RM) conio.pce + $(RM) conio.map test: conio.pce mednafen -force_module pce conio.pce diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 44da30a2a..d22fe58ee 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -33,13 +33,13 @@ void main(void) cprintf("stackvar: %02x\n\r", stackvar); j = joy_count(); - gotoxy(0,10); + gotoxy(0,9); cprintf("Found %d Joysticks.", j); for (i = 0; i < 4; ++i) { - gotoxy(0, 17 + i); + gotoxy(0, 16 + i); p = malloc(16); - memcpy(p, "01234567890abcdef", 16); + memcpy(p, "0123456789abcdef", 16); cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] @@ -88,12 +88,12 @@ void main(void) cprintf("%02x", stackvar); ++datavar; ++stackvar; - gotoxy(0,8); + gotoxy(0,7); clk = clock(); cprintf("clock: %08lx", clk); for (i = 0; i < 4; ++i) { - gotoxy(0, 12 + i); + gotoxy(0, 11 + i); j = joy_read (i); cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", i, j, From 088a25437dfff9717c1a554530967a96bcaab127 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 7 Sep 2015 12:55:36 +0200 Subject: [PATCH 25/28] fixed VDC register assignments --- asminc/pce.inc | 38 ++++++++++++++++++++------------------ libsrc/pce/conio.s | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 9a77bcc4e..3e82c38cc 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -18,27 +18,29 @@ charsperline = 61 CH_HLINE = 1 CH_VLINE = 2 -; huc6270 - Video Display Controller (vdc) +; huc6270 - Video Display Controller (VDC) VDC_MAWR = 0 ; Memory Address Write Register VDC_MARR = 1 ; Memory Address Read Register -VDC_VWR = 2 ; VRAM Write Register -VDC_VRR = 3 ; VRAM Read Register -VDC_CR = 4 ; Control Register -VDC_RCR = 5 ; Raster Counter Register -VDC_BXR = 6 ; Background X-Scroll Register -VDC_BYR = 7 ; Background Y-Scroll Register -VDC_MWR = 8 ; Memory-access Width Register -VDC_HSR = 9 ; Horizontal Sync Register (?) -VDC_HDR = 10 ; Horizontal Display Register (?) -VDC_VPR = 11 ; (unknown) -VDC_VDW = 12 ; (unknown use) -VDC_VCR = 13 ; (unknown use) -VDC_DCR = 14 ; (DMA) Control Register -VDC_SOUR = 15 ; (DMA) Source Register -VDC_DESR = 16 ; (DMA) Destination Register -VDC_LENR = 17 ; (DMA) Length Register -VDC_SATB = 18 ; Sprite Attribute Table +VDC_VWR = 2 ; VRAM Write Register (write only) +VDC_VRR = 2 ; VRAM Read Register (read only) +VDC_UNK03 = 3 ; (unknown) +VDC_UNK04 = 4 ; (unknown) +VDC_CR = 5 ; Control Register +VDC_RCR = 6 ; Raster Counter Register +VDC_BXR = 7 ; Background X-Scroll Register +VDC_BYR = 8 ; Background Y-Scroll Register +VDC_MWR = 9 ; Memory-access Width Register +VDC_HSR = 10 ; Horizontal Sync Register +VDC_HDR = 11 ; Horizontal Display Register +VDC_VPR = 12 ; Vertical synchronous register +VDC_VDW = 13 ; Vertical display register +VDC_VCR = 14 ; Vertical display END position register +VDC_DCR = 15 ; (DMA) Control Register +VDC_SOUR = 16 ; (DMA) Source Register +VDC_DESR = 17 ; (DMA) Destination Register +VDC_LENR = 18 ; (DMA) Length Register +VDC_SATB = 19 ; Sprite Attribute Table ; VDC port ; Note: absolute addressing mode must be used when writing to this port diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index b9333e1fa..a8565a6ae 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -14,7 +14,7 @@ initconio: jsr conio_init jsr set_palette - st0 #VDC_RCR + st0 #VDC_CR st1 #<$0088 st2 #>$0088 rts From 859604407b76364c129e106833fda674ab44ef92 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 19 Sep 2015 15:37:39 +0200 Subject: [PATCH 26/28] fixed more flaws found by greg :) --- asminc/pce.inc | 9 --------- cfg/pce.cfg | 4 +++- libsrc/pce/clock.s | 1 + libsrc/pce/clrscr.s | 8 +++++++- libsrc/pce/color.s | 6 ++++-- libsrc/pce/conio.s | 1 + libsrc/pce/cputc.s | 1 + libsrc/pce/crt0.s | 3 ++- libsrc/pce/extzp.inc | 17 +++++++++++++++++ libsrc/pce/extzp.s | 17 +++++++++++++++++ libsrc/pce/gotoxy.s | 1 + libsrc/pce/kplot.s | 1 + libsrc/pce/revers.s | 3 ++- libsrc/pce/waitvblank.s | 1 + 14 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 libsrc/pce/extzp.inc create mode 100644 libsrc/pce/extzp.s diff --git a/asminc/pce.inc b/asminc/pce.inc index 3e82c38cc..623ab4da8 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -2,15 +2,6 @@ ; PCE definitions. By Groepaz/Hitmem. ; -; FIXME: optimize zeropage usage -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 ;2 -CHARCOLOR = $34 -RVS = $35 -BGCOLOR = $36 -tickcount = $37 ;4 - ; FIXME: screen dimensions my change according to selected video mode screenrows = (224/8) charsperline = 61 diff --git a/cfg/pce.cfg b/cfg/pce.cfg index adb420f32..2c660435a 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -6,7 +6,7 @@ SYMBOLS { MEMORY { # FIXME: is this correct? the first 3? bytes cant be used? - ZP: start = $03, size = $1A, type = rw, define = yes; + ZP: start = $03, size = $fd, type = rw, define = yes; # reset-bank and hardware vectors ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; @@ -25,6 +25,8 @@ SEGMENTS { BSS: load = RAM, type = bss, define = yes; VECTORS: load = ROMV, type = rw, define = yes; ZEROPAGE: load = ZP, type = zp, define = yes; + EXTZP: load = ZP, type = zp, define = yes, optional = yes; + APPZP: load = ZP, type = zp, define = yes, optional = yes; } FEATURES { diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 6b14232fe..d92ebe89f 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -3,6 +3,7 @@ ; .include "pce.inc" + .include "extzp.inc" .export _clock .importzp sreg diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index eae2b27a2..f198be714 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,6 +1,8 @@ .include "pce.inc" + .include "extzp.inc" + .import PLOT .export _clrscr _clrscr: @@ -23,7 +25,11 @@ colloop: dey bne rowloop - rts +; Go to the home position. + + stz CURS_X + stz CURS_Y + jmp PLOT ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 36c85b6b5..0ff991a2e 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -7,7 +7,8 @@ .export _textcolor, _bgcolor, _bordercolor - .include "pce.inc" + .include "pce.inc" + .include "extzp.inc" _textcolor: ldx CHARCOLOR ; get old value @@ -33,9 +34,10 @@ _bgcolor: _bordercolor: lda #0 - txa + tax rts + .rodata .export colors colors: diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index a8565a6ae..bcfc600a7 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,4 +1,5 @@ .include "pce.inc" + .include "extzp.inc" .import vce_init .import psg_init diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index d31e13769..8d1cec8eb 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -12,6 +12,7 @@ .importzp tmp3,tmp4 .include "pce.inc" + .include "extzp.inc" _cputcxy: pha ; Save C diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index f89119c46..4f886ca5a 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -26,6 +26,7 @@ .import __BSS_SIZE__ .include "pce.inc" + .include "extzp.inc" .importzp sp .importzp ptr1,ptr2 @@ -77,7 +78,7 @@ start: tii $2000, $2001, $1FFF ; Initialize hardware - stz TIMER_COUNT ; Timer off + stz TIMER_CTRL ; Timer off lda #$07 sta IRQ_MASK ; Interrupts off stz IRQ_STATUS ; Acknowledge timer diff --git a/libsrc/pce/extzp.inc b/libsrc/pce/extzp.inc new file mode 100644 index 000000000..2869c3a06 --- /dev/null +++ b/libsrc/pce/extzp.inc @@ -0,0 +1,17 @@ +; +; extzp.inc for the PC-Engine +; +; Groepaz/Hitmen, 2015-11-19 +; +; Assembler include file that imports the runtime zero page locations used +; by the PC-Engine runtime, ready for usage in asm code. +; + + + .global CURS_X: zp + .global CURS_Y: zp + .global SCREEN_PTR: zp + .global CHARCOLOR: zp + .global RVS: zp + .global BGCOLOR: zp + .global tickcount: zp diff --git a/libsrc/pce/extzp.s b/libsrc/pce/extzp.s new file mode 100644 index 000000000..516c30954 --- /dev/null +++ b/libsrc/pce/extzp.s @@ -0,0 +1,17 @@ +; +; Groepaz/Hitmen, 2015-11-19 +; +; zeropage locations for exclusive use by the library +; + + .include "extzp.inc" + + .segment "EXTZP" : zeropage + +CURS_X: .res 1 +CURS_Y: .res 1 +SCREEN_PTR: .res 2 +CHARCOLOR: .res 1 +RVS: .res 1 +BGCOLOR: .res 1 +tickcount: .res 4 diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index c7cda83f3..fb61646d1 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -6,6 +6,7 @@ .import popa, plot .include "pce.inc" + .include "extzp.inc" _gotoxy: sta CURS_Y ; Set Y diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index 24ae8fab7..6c81e4152 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -2,6 +2,7 @@ .export PLOT .include "pce.inc" + .include "extzp.inc" PLOT: bcs @getpos diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index 1773de2b0..17a74508c 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,6 @@ - .include "pce.inc" + .include "pce.inc" + .include "extzp.inc" .export _revers diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index b4e31f45a..d60a9ddea 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -3,6 +3,7 @@ ; .include "pce.inc" + .include "extzp.inc" .export _waitvblank From 296489ba6cf76c38e242bd601e18f31495cf65f1 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 19 Sep 2015 15:55:43 +0200 Subject: [PATCH 27/28] added interruptor support --- cfg/pce.cfg | 11 +++++----- libsrc/pce/clock.s | 1 + libsrc/pce/crt0.s | 40 +++++----------------------------- libsrc/pce/extzp.inc | 1 + libsrc/pce/extzp.s | 1 + libsrc/pce/irq.s | 48 +++++++++++++++++++++++++++++++++++++++++ libsrc/pce/ticktock.s | 18 ++++++++++++++++ libsrc/pce/waitvblank.s | 1 + 8 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 libsrc/pce/irq.s create mode 100644 libsrc/pce/ticktock.s diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 2c660435a..9128eb727 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -38,10 +38,9 @@ FEATURES { label = __DESTRUCTOR_TABLE__, count = __DESTRUCTOR_COUNT__, segment = RODATA; -# FIXME: interruptor support is missing -# CONDES: type = interruptor, -# label = __INTERRUPTOR_TABLE__, -# count = __INTERRUPTOR_COUNT__, -# segment = RODATA, -# import = __CALLIRQ__; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; } diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index d92ebe89f..c6d6fb7fb 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -5,6 +5,7 @@ .include "pce.inc" .include "extzp.inc" + .forceimport ticktock .export _clock .importzp sreg diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 4f886ca5a..77872f32f 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -13,7 +13,7 @@ .import initlib, donelib .import push0, _main, zerobss .import initheap - .import tmp1,tmp2,tmp3 + .import IRQStub ; Linker generated .import __RAM_START__, __RAM_SIZE__ @@ -30,6 +30,7 @@ .importzp sp .importzp ptr1,ptr2 + .importzp tmp1,tmp2,tmp3 ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. @@ -158,39 +159,8 @@ _exit: ; reset the PCEngine (start over) jmp start -; ------------------------------------------------------------------------ -; System V-Blank Interupt -; FIXME: hooks should be provided so the user can abuse the IRQ -; ------------------------------------------------------------------------ - -_irq1: - pha - phx - phy - - ; increment the system tick counter - inc tickcount - bne @s1 - inc tickcount + 1 - bne @s1 - inc tickcount + 2 - bne @s1 - inc tickcount + 3 -@s1: - ; Acknowlege interrupt - lda a:VDC_CTRL - - ply - plx - pla - rti -_irq2: - rti _nmi: rti -_timer: - stz IRQ_STATUS - rti .export initmainargs initmainargs: @@ -201,8 +171,8 @@ initmainargs: ; ------------------------------------------------------------------------ .segment "VECTORS" - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer + .word IRQStub ; $fff6 IRQ2 (External IRQ, BRK) + .word IRQStub ; $fff8 IRQ1 (VDC) + .word IRQStub ; $fffa Timer .word _nmi ; $fffc NMI .word start ; $fffe reset diff --git a/libsrc/pce/extzp.inc b/libsrc/pce/extzp.inc index 2869c3a06..dce91558f 100644 --- a/libsrc/pce/extzp.inc +++ b/libsrc/pce/extzp.inc @@ -15,3 +15,4 @@ .global RVS: zp .global BGCOLOR: zp .global tickcount: zp + .global vdc_flags: zp diff --git a/libsrc/pce/extzp.s b/libsrc/pce/extzp.s index 516c30954..26dc589b1 100644 --- a/libsrc/pce/extzp.s +++ b/libsrc/pce/extzp.s @@ -15,3 +15,4 @@ CHARCOLOR: .res 1 RVS: .res 1 BGCOLOR: .res 1 tickcount: .res 4 +vdc_flags: .res 1 diff --git a/libsrc/pce/irq.s b/libsrc/pce/irq.s new file mode 100644 index 000000000..f34303d07 --- /dev/null +++ b/libsrc/pce/irq.s @@ -0,0 +1,48 @@ +; +; IRQ handling (PCE version) +; + + .export initirq, doneirq, IRQStub + + .import __INTERRUPTOR_COUNT__, callirq_y + + .include "pce.inc" + .include "extzp.inc" + +; ------------------------------------------------------------------------ +.segment "INIT" + +; a constructor +; +initirq: + rts + +; ------------------------------------------------------------------------ +.code + +; a destructor +; +doneirq: + rts + +; ------------------------------------------------------------------------ + +IRQStub: + phy + +; Save the display-source flags (and, release the interrupt). +; + ldy a:VDC_CTRL + sty vdc_flags + + ldy #<(__INTERRUPTOR_COUNT__ * 2) + beq @L1 + phx + pha + + jsr callirq_y + + pla + plx +@L1: ply + rti diff --git a/libsrc/pce/ticktock.s b/libsrc/pce/ticktock.s new file mode 100644 index 000000000..4e4d44d9a --- /dev/null +++ b/libsrc/pce/ticktock.s @@ -0,0 +1,18 @@ + .interruptor ticktock, 24 + + .include "pce.inc" + .include "extzp.inc" + +ticktock: + bbr5 vdc_flags,@s1 ; not vertical-blank interrupt + + ; Increment the system tick counter. + inc tickcount + bne @s1 + inc tickcount+1 + bne @s1 + inc tickcount+2 + bne @s1 + inc tickcount+3 + +@s1: rts diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index d60a9ddea..b9f0f902f 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -5,6 +5,7 @@ .include "pce.inc" .include "extzp.inc" + .forceimport ticktock .export _waitvblank .proc _waitvblank From 7d453a72fb16f8a26a8a0443ccb34fe3927a98f8 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 20 Sep 2015 12:18:41 +0200 Subject: [PATCH 28/28] use 'plot' instead of 'PLOT' --- libsrc/pce/clrscr.s | 4 ++-- libsrc/pce/kplot.s | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index f198be714..e3f40bb8b 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -2,7 +2,7 @@ .include "pce.inc" .include "extzp.inc" - .import PLOT + .import plot .export _clrscr _clrscr: @@ -29,7 +29,7 @@ colloop: stz CURS_X stz CURS_Y - jmp PLOT + jmp plot ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index 6c81e4152..e4426d005 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -8,7 +8,7 @@ PLOT: bcs @getpos tya - clc + ;clc ; already cleared adc _plotlo,x sta SCREEN_PTR