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_DATA_LO := $0202
VDC_DATA_HI := $0203
-; huc6260 - Video Color Encoder (vce)
+; 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.
+; The bitmap of the palette data is this: 0000000gggrrrbbb.
+; You can read and write the DAC registers.
VCE = $0400 ; base
-VCE_CTRL = $0400 ; write$00 to reset
+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)
+; Programmable Sound Generator (PSG)
PSG = $0800 ; base
PSG_LFO_FREQ = $0808
PSG_LFO_CTRL = $0809
-; timer
+; Timer
-TIMER = $0c00 ; base
+TIMER = $0C00 ; base
-TIMER_COUNT = $0c00
-TIMER_CTRL = $0c01
+TIMER_COUNT = $0C00
+TIMER_CTRL = $0C01
JOY_CTRL = $1000
-# linker config. to produce a NEC PC-Engine 8K, 16K, or 32K image (.bin)
+# Linker config. to produce a NEC PC-Engine 8K, 16K, or 32K image (.bin)
SYMBOLS {
__CARTSIZE__: type = weak, value = $2000; # $2000, $4000, or $8000
__STACKSIZE__: type = weak, value = $0300; # 3 pages stack
<article>
-<title>PC-Engine (TurboGrafx) System specific information for cc65
+<title>PC-Engine (TurboGrafx 16) System-specific information for cc65
<author><url url="mailto:groepaz@gmx.net" name="Groepaz/Hitmen">,<newline>
<url url="mailto:greg.king5@verizon.net" name="Greg King">
-<date>2018-02-12
+<date>2018-02-24
<abstract>
An overview over the PCE runtime system as it is implemented for the
<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
+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
+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" might be available on
more than one platform. Please see the function reference for more
information.
<sect>Memory layout<p>
-cc65 generated programs with the default setup run with the I/O area and a
+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.
<descrip>
<tag/Text screen and Font/
- The text screen is located at VRAM $0000,
+ 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.
+ The C runtime stack is located in system RAM at $3FFF; and, grows downwards.
<tag/Data and BSS/
The Data (initialized variables) and BSS (uninitialized variables) sections are
-<sect>Platform specific header files<p>
+<sect>Platform-specific header files<p>
-Programs containing PCE specific code may use the <tt/pce.h/ header file.
+Programs containing PCE-specific code may use the <tt/pce.h/ header file.
-<sect1>PCE specific functions<p>
+<sect1>PCE-specific functions<p>
<itemize>
<item>waitvsync</item>
</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.
+The following pseudo variables, declared in the <tt/pce.inc/ include file, do
+allow access to hardware that is located in the address space.
<descrip>
<descrip>
<tag><tt/pce-stdjoy.joy (pce_stdjoy)/</tag>
- A joystick driver for the standard two buttons joypad is available.
+ A joystick driver for the standard two-button joypad is available.
- Note that the japanese 6-button pad is currently not supported.
+ Note that the Japanese 6-button pad currently is not supported.
</descrip><p>
<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
<item>...
</itemize>
+
+
<sect>Other hints<p>
<itemize>
emulator to use for the PC-Engine.
</itemize>
-some useful resources on PCE coding:
+Some useful resources on PCE coding:
<itemize>
<item><url url="http://blog.blockos.org/?tag=pc-engine">
<item><url url="http://www.zeograd.com/parse.php?src=hucf">
</itemize>
+
+
<sect>License<p>
-This software is provided 'as-is', without any expressed or implied
+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.
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.
+<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 marked plainly 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>
/* */
/* pce.h */
/* */
-/* PC-Engine system specific definitions */
+/* PC-Engine system-specific definitions */
/* */
/* */
/* */
-/* (C) 2015 Groepaz/Hitmen */
+/* (C) 2015, Groepaz/Hitmen */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#define CH_ENTER 13
#define CH_PI 18
-/* Color defines (CBM compatible, for conio) */
+/* Color defines (CBM-compatible, for conio) */
#define COLOR_BLACK 0x00
#define COLOR_WHITE 0x01
#define COLOR_RED 0x02
void waitvsync (void);
/* Wait for start of the next frame */
-/* NOTE: all PCE are NTSC */
+/* NOTE: all PCEs are NTSC. */
#define get_tv() TV_NTSC
/* Return the video mode the machine is using. */
;
; Screen size variables
;
+ .export screensize
+ .export xsize, ysize
+
.include "pce.inc"
- .export screensize
screensize:
ldx xsize
ldy ysize
; FIXME: changing the video mode allows for different screen sizes
.rodata
- .export xsize, ysize
xsize: .byte charsperline
ysize: .byte screenrows
;
.export _chlinexy, _chline
+
.import gotoxy, cputdirect
.importzp tmp1
dec tmp1
bne L1
L9: rts
-
-
-
-
; clock_t clock (void);
;
- .include "pce.inc"
- .include "extzp.inc"
-
.export _clock
+ .constructor initclock, 24
+
.forceimport ticktock
.importzp sreg
- .constructor initclock
+ .include "extzp.inc"
.proc _clock
-
lda tickcount+3
sta sreg+1
lda tickcount+2
ldx tickcount+1
lda tickcount
rts
-
.endproc
.segment "ONCE"
+ .export _clrscr
+
+ .import plot
.include "pce.inc"
.include "extzp.inc"
- .import plot
- .export _clrscr
_clrscr:
-
st0 #VDC_MAWR
st1 #<$0000
st2 #>$0000
; unsigned char __fastcall__ bordercolor (unsigned char color);
;
-
.export _textcolor, _bgcolor, _bordercolor
+ .export colors
+
.import return0
.include "pce.inc"
.include "extzp.inc"
-_bordercolor = return0
+_bordercolor := return0
_textcolor:
ldx CHARCOLOR ; get old value
txa
rts
- .rodata
- .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
+.rodata
+
+ ; G R B
+colors: .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
- .include "pce.inc"
- .include "extzp.inc"
+ .constructor initconio, 24
.import vce_init
.import psg_init
+ .import vdc_init
.import colors
.importzp ptr1, tmp1
- .constructor initconio
-
+ .include "pce.inc"
+ .include "extzp.inc"
.macpack longbranch
.segment "ONCE"
inx
inx
- cpx #16*2
+ cpx #16 * 2
jne @lp
stz VCE_ADDR_LO
lda #>font
sta ptr1+1
- lda #$ff
+ lda #$FF
sta tmp1
jsr copy
rts
-font:
- .include "vga.inc"
+.rodata
+font: .include "vga.inc"
.export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot
+
.import gotoxy
.import PLOT
.import xsize
-
- .importzp tmp3,tmp4
+ .importzp tmp3, tmp4
.include "pce.inc"
.include "extzp.inc"
; Plot a character - also used as internal function
-_cputc: cmp #$0d ; CR?
+_cputc: cmp #$0D ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
-L1: cmp #$0a ; LF?
+L1: cmp #$0A ; LF?
beq newline ; Recalculate pointers
; Printable char of some sort
cpy xsize
bne L3
jsr newline ; new line
- ldy #0 ; + cr
+ ldy #0 ; + CR
L3: sty CURS_X
jmp plot
lda SCREEN_PTR
sta VDC_DATA_LO
- lda SCREEN_PTR + 1
+ lda SCREEN_PTR+1
sta VDC_DATA_HI
st0 #VDC_VWR ; VWR
;
; Startup code for cc65 (PCEngine version)
;
-; by Groepaz/Hitmen <groepaz@gmx.net>
-; based on code by Ullrich von Bassewitz <uz@cc65.org>
+; by Groepaz/Hitmen <groepaz@gmx.net>,
+; based on code by Ullrich von Bassewitz <uz@cc65.org>.
;
; 2018-02-11, Greg King
;
; ------------------------------------------------------------------------
; Place the startup code in a special segment.
- .segment "STARTUP"
-
-start:
-
- ; Set up the CPU and System-IRQ
+.segment "STARTUP"
; Initialize CPU
- sei
+start: sei
nop
- csh ; Set high speed CPU mode
+ csh ; Set high-speed CPU mode
nop
; Set up stack and memory mapping
inc a
@L1: tam #%01000000 ; $C000-$DFFF = ROM bank 3 (32K) or 1 (16K)
;lda #$00 ; (The reset default)
- ;tam #%10000000 ; $E000-$FFFF hucard/syscard bank 0
+ ;tam #%10000000 ; $E000-$FFFF Hucard/Syscard bank 0
; Initialize hardware
stz TIMER_CTRL ; Timer off
sta IRQ_MASK ; Interrupts off
stz IRQ_STATUS ; Acknowledge timer
- ; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/
+ ; FIXME; I don't know why the heck this one doesn't work when called from a constructor. :/
.import vdc_init
jsr vdc_init
; 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
ldy #4 ; Argument size
- jsr _main ; Call the users code
+ jsr _main ; Call the user's code
; Call module destructors. This is also the _exit entry.
-_exit:
- jsr donelib ; Run module destructors
+_exit: jsr donelib ; Run module destructors
; reset the PCEngine (start over)
jmp start
-_nmi:
- rti
+_nmi: rti
.export initmainargs
initmainargs:
; ------------------------------------------------------------------------
; hardware vectors
; ------------------------------------------------------------------------
- .segment "VECTORS"
+.segment "VECTORS"
- .word IRQStub ; $fff6 IRQ2 (External IRQ, BRK)
- .word IRQStub ; $fff8 IRQ1 (VDC)
- .word IRQStub ; $fffa Timer
- .word _nmi ; $fffc NMI
- .word start ; $fffe reset
+ .word IRQStub ; $FFF6 IRQ2 (External IRQ, BRK)
+ .word IRQStub ; $FFF8 IRQ1 (VDC)
+ .word IRQStub ; $FFFA Timer
+ .word _nmi ; $FFFC NMI
+ .word start ; $FFFE reset
.rodata
-; The following 256 byte wide table specifies attributes for the isxxx type
+; 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:
;
.byte CT_NONE ; 126/7e _____~_____
.byte CT_OTHER_WS ; 127/7f ____DEL____
.endrepeat
-
-
;
.export _cvlinexy, _cvline
+
.import gotoxy, putchar, newline
.importzp tmp1
dec tmp1
bne L1
L9: rts
-
-
-
; zeropage locations for exclusive use by the library
;
- .include "extzp.inc"
+ .include "extzp.inc"
- .segment "EXTZP" : zeropage
+.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
-vdc_flags: .res 1
+CURS_X: .res 1
+CURS_Y: .res 1
+SCREEN_PTR: .res 2
+CHARCOLOR: .res 1
+RVS: .res 1
+BGCOLOR: .res 1
+tickcount: .res 4
+vdc_flags: .res 1
;
.export gotoxy, _gotoxy
+
.import popa, plot
.include "pce.inc"
-
;
; Standard joystick driver for the PCEngine
;
; Driver signature
- .byte $6A, $6F, $79 ; "joy"
- .byte JOY_API_VERSION ; Driver API version number
+ .byte $6A, $6F, $79 ; "joy"
+ .byte JOY_API_VERSION ; Driver API version number
; Library reference
; 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.
+; Must return a JOY_ERR_xx code in a/x.
;
INSTALL:
rts
read_joy:
- ; reset multitap counter
+ ; Reset Multitap counter.
lda #$01
sta JOY_CTRL
pha
cly
nextpad:
lda #$01
- sta JOY_CTRL ; sel = 1
+ sta JOY_CTRL ; sel = 1
pha
pla
nop ; some delay is required
asl a
asl a
asl a
- sta padbuffer, y ; store new value
+ sta padbuffer,y ; store new value
stz JOY_CTRL
pha
pla
-
nop ; some delay is required
nop
lda JOY_CTRL
and #$0F
- ora padbuffer, y ; second half of new value
+ ora padbuffer,y ; second half of new value
eor #$FF
- sta padbuffer, y ; store new value
+ sta padbuffer,y ; store new value
iny
cpy #$05
padbuffer:
.res 4
-
ldy CURS_X
rts
- .rodata
+.rodata
_plotlo:
.repeat screenrows,line
- .include "pce.inc"
-
.export psg_init
+ .include "pce.inc"
+
.segment "ONCE"
psg_init:
clx
+ .export _revers
+
.include "pce.inc"
.include "extzp.inc"
- .export _revers
-
.proc _revers
-
ldx #$00 ; Assume revers off
tay ; Test onoff
beq L1 ; Jump if off
L2: ldx #$00 ; Load high byte of result
tya ; Load low byte, set CC
rts
-
.endproc
;-------------------------------------------------------------------------------
- .include "pce.inc"
-
.export vce_init
+ .include "pce.inc"
+
.segment "ONCE"
vce_init:
; Set CTA to zero
+ .export vdc_init
+
.include "pce.inc"
; FIXME: implement selection of different video modes at runtime
HIRES = 1
- .export vdc_init
-
vdc_init:
lda VDC_CTRL
; void waitvsync (void);
;
- .include "pce.inc"
- .include "extzp.inc"
+ .export _waitvsync
.forceimport ticktock
- .export _waitvsync
-.proc _waitvsync
+ .include "pce.inc"
+ .include "extzp.inc"
+.proc _waitvsync
lda tickcount
@lp: cmp tickcount
beq @lp
rts
-
.endproc