Merge pull request #122 from groessler/a5200

new target: Atari 5200 console
This commit is contained in:
Oliver Schmidt
2014-05-30 22:52:51 +02:00
45 changed files with 1480 additions and 227 deletions

View File

@@ -18,6 +18,7 @@ TARGETS = apple2 \
apple2enh \
atari \
atarixl \
atari5200 \
atmos \
$(CBMS) \
$(GEOS) \

View File

@@ -9,6 +9,12 @@
.import popa, _gotoxy, cputdirect, setcursor
.importzp tmp1
.ifndef __ATARI5200__
CHRCODE = $12+64
.else
CHRCODE = 14
.endif
_chlinexy:
pha ; Save the length
jsr popa ; Get y
@@ -19,12 +25,8 @@ _chline:
cmp #0 ; Is the length zero?
beq L9 ; Jump if done
sta tmp1
L1: lda #$12+64 ; Horizontal line, screen code
L1: lda #CHRCODE ; Horizontal line, screen code
jsr cputdirect ; Direct output
dec tmp1
bne L1
L9: jmp setcursor

View File

@@ -10,6 +10,12 @@
.import popa, _gotoxy, putchar, setcursor
.importzp tmp1
.ifndef __ATARI5200__
CHRCODE = $7C ; Vertical bar
.else
CHRCODE = 1 ; exclamation mark
.endif
_cvlinexy:
pha ; Save the length
jsr popa ; Get y
@@ -22,7 +28,7 @@ _cvline:
sta tmp1
L1: lda COLCRS
pha
lda #$7C ; Vertical bar
lda #CHRCODE ; Vertical bar
jsr putchar ; Write, no cursor advance
pla
sta COLCRS
@@ -30,6 +36,3 @@ L1: lda COLCRS
dec tmp1
bne L1
L9: jmp setcursor

View File

@@ -0,0 +1,13 @@
; Cartridge entry point
;
; Christian Groessler, 01-Mar-2014
.export __CART_ENTRY__: absolute = 1
.import __CARTSIZE__, start
.forceimport __CART_YEAR__, __CART_NAME__
.segment "CARTENTRY"
.word start ; entry point
.assert (__CARTSIZE__ = $4000 || __CARTSIZE__ = $8000), error, "Cartridge size must either be $4000 or $8000"

View File

@@ -0,0 +1,13 @@
; default cartridge name
;
; Christian Groessler, 01-Mar-2014
.include "atari.mac"
.export __CART_NAME__: absolute = 1
.segment "CARTNAME"
scrcode " cc"
.byte '6' + 32, '5' + 32 ; use playfield 1
scrcode " compiled"

View File

@@ -0,0 +1,9 @@
; Cartridge copyright year
;
; Christian Groessler, 01-Mar-2014
.export __CART_YEAR__: absolute = 1
.segment "CARTYEAR"
.byte '9' + 32,'8' + 32 ; "98", but using playfield 1

View File

@@ -0,0 +1 @@
.include "../atari/cclear.s"

View File

@@ -0,0 +1 @@
.include "../atari/chline.s"

26
libsrc/atari5200/clock.s Normal file
View File

@@ -0,0 +1,26 @@
;
; from Atari computer version by Christian Groessler, 2014
;
; clock_t clock (void);
; unsigned _clocks_per_sec (void);
;
.export _clock
.importzp sreg
.include "atari5200.inc"
.proc _clock
ldx #5 ; Synchronize with Antic, so the interrupt won't change RTCLOK
stx WSYNC ; while we're reading it. The synchronization is done same as
@L1: dex ; in SETVBLV function in Atari OS.
bne @L1
stx sreg+1 ; Byte 3 is always zero
stx sreg ; Byte 2 is always zero, too
lda RTCLOK+1
ldx RTCLOK
rts
.endproc

34
libsrc/atari5200/clrscr.s Normal file
View File

@@ -0,0 +1,34 @@
;
; Christian Groessler, May-2014
;
; void clrscr (void);
;
.export _clrscr
.include "atari5200.inc"
.importzp ptr1
SCRSIZE = 480 ; 20x24: size of default conio atari5200 screen
_clrscr:lda SAVMSC ; screen memory
sta ptr1
lda SAVMSC+1
clc
adc #>(SCRSIZE-1)
sta ptr1+1
lda #0 ; screen code of space char
ldy #<(SCRSIZE-1)
ldx #>(SCRSIZE-1)
_clr1: sta (ptr1),y
dey
bne _clr1
sta (ptr1),y
dex
bmi done
dec ptr1+1
dey
jmp _clr1
done: sta COLCRS_5200
sta ROWCRS_5200
rts

View File

@@ -0,0 +1,83 @@
; setup default CONIO screen (20x24, Antic mode 6, BASIC mode 1)
;
; 28-May-2014, Christian Groessler <chris@groessler.org>
.include "atari5200.inc"
SCREEN_BUF_SIZE = 20 * 24
SCREEN_BUF = $4000 - SCREEN_BUF_SIZE
.code
.export screen_setup_20x24
screen_setup_20x24:
; initialize SAVMSC
lda #<SCREEN_BUF
sta SAVMSC
lda #>SCREEN_BUF
sta SAVMSC+1
; initialize cursor position
lda #0
sta COLCRS_5200
sta ROWCRS_5200
; clear screen buffer
ldy #<(SCREEN_BUF_SIZE-1)
ldx #>(SCREEN_BUF_SIZE-1)
clrscr: sta (SAVMSC),y
dey
cpy #$FF
bne clrscr
dex
cpx #$FF
bne clrscr
; set default colors
lda #40
sta COLOR0
lda #202
sta COLOR1
lda #148
sta COLOR2
lda #70
sta COLOR3
lda #0
sta COLOR4
; set display list
lda #<dlist
sta SDLSTL
lda #>dlist
sta SDLSTH
rts
.segment "RODATA"
; display list for 20x24 text mode
dlist: .repeat 3
.byte DL_BLK8
.endrepeat
.byte DL_CHR20x8x2 | DL_LMS
.word SCREEN_BUF
.repeat 23
.byte DL_CHR20x8x2
.endrepeat
.byte DL_JVB
.word dlist
; end of display list
.assert ((* >> 10) = (dlist >> 10)), error, "Display list crosses 1K boundary"
.end

94
libsrc/atari5200/cputc.s Normal file
View File

@@ -0,0 +1,94 @@
;
; adapted from Atari version
; Christian Groessler, 2014
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
;
.include "atari5200.inc"
.export _cputcxy, _cputc
.export plot, cputdirect, putchar
.import popa, _gotoxy, mul20
.importzp ptr4
.import setcursor
.constructor screen_setup, 26
.import screen_setup_20x24
screen_setup = screen_setup_20x24
_cputcxy:
pha ; Save C
jsr popa ; Get Y
jsr _gotoxy ; Set cursor, drop x
pla ; Restore C
_cputc:
cmp #$0D ; CR
bne L4
lda #0
sta COLCRS_5200
beq plot ; return
L4: cmp #$0A ; LF
beq newline
cmp #ATEOL ; Atari-EOL?
beq newline
tay
rol a
rol a
rol a
rol a
and #3
tax
tya
and #$9f
ora ataint,x
cputdirect: ; accepts screen code
jsr putchar
; advance cursor
inc COLCRS_5200
lda COLCRS_5200
cmp #20
bcc plot
lda #0
sta COLCRS_5200
.export newline
newline:
inc ROWCRS_5200
lda ROWCRS_5200
cmp #24
bne plot
lda #0
sta ROWCRS_5200
plot: jsr setcursor
ldy COLCRS_5200
ldx ROWCRS_5200
rts
putchar:
pha ; save char
lda ROWCRS_5200
jsr mul20 ; destroys tmp4
clc
adc SAVMSC ; add start of screen memory
sta ptr4
txa
adc SAVMSC+1
sta ptr4+1
pla ; get char again
ldy COLCRS_5200
sta (ptr4),y
jmp setcursor
.rodata
ataint: .byte 64,0,32,96

48
libsrc/atari5200/crt0.s Normal file
View File

@@ -0,0 +1,48 @@
;
; Startup code for cc65 (Atari5200 version)
;
; Christian Groessler (chris@groessler.org), 2014
;
.export _exit, start
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import __RAM_START__, __RAM_SIZE__
.import __RESERVED_MEMORY__
.import initlib, donelib, callmain
.import zerobss, copydata
.include "zeropage.inc"
.include "atari5200.inc"
start:
; Clear the BSS data
jsr zerobss
; initialize data
jsr copydata
; setup the stack
lda #<(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
sta sp+1 ; Set argument stack ptr
; Call module constructors
jsr initlib
; Push arguments and call main()
jsr callmain
; Call module destructors. This is also the _exit entry.
_exit: jsr donelib ; Run module destructors
; A 5200 program isn't supposed to exit.
halt: jmp halt

5
libsrc/atari5200/ctype.s Normal file
View File

@@ -0,0 +1,5 @@
; Character specification table.
;
; same as for "atari" target
.include "../atari/ctype.s"

View File

@@ -0,0 +1 @@
.include "../atari/cvline.s"

20
libsrc/atari5200/get_tv.s Normal file
View File

@@ -0,0 +1,20 @@
;
; Christian Groessler, 2014
;
; unsigned char get_tv (void);
; /* Return the video mode the machine is using */
;
.include "get_tv.inc"
;--------------------------------------------------------------------------
; _get_tv
.proc _get_tv
lda #<TV::NTSC
ldx #>TV::NTSC
rts
.endproc

13
libsrc/atari5200/gotox.s Normal file
View File

@@ -0,0 +1,13 @@
;
; Christian Groessler, 13-Mar-2014
;
; void gotox (unsigned char x);
;
.include "atari5200.inc"
.export _gotox
.import setcursor
_gotox:
sta COLCRS_5200 ; Set X
jmp setcursor

17
libsrc/atari5200/gotoxy.s Normal file
View File

@@ -0,0 +1,17 @@
;
; Christian Groessler, 13-Mar-2014
;
; void gotoxy (unsigned char x, unsigned char y);
;
.include "atari5200.inc"
.export _gotoxy
.import popa
.import setcursor
_gotoxy: ; Set the cursor position
sta ROWCRS_5200 ; Set Y
jsr popa ; Get X
sta COLCRS_5200 ; Set X
jmp setcursor

13
libsrc/atari5200/gotoy.s Normal file
View File

@@ -0,0 +1,13 @@
;
; Christian Groessler, 13-Mar-2014
;
; void gotoy (unsigned char y);
;
.include "atari5200.inc"
.export _gotoy
.import setcursor
_gotoy:
sta ROWCRS_5200 ; Set Y
jmp setcursor

59
libsrc/atari5200/irq.s Normal file
View File

@@ -0,0 +1,59 @@
;
; IRQ handling (ATARI 5200 version)
;
.export initirq, doneirq
.import callirq
.include "atari5200.inc"
; ------------------------------------------------------------------------
.segment "INIT"
initirq:
lda VVBLKD
ldx VVBLKD+1
sta IRQInd+1
stx IRQInd+2
ldy #<IRQStub
ldx #>IRQStub
jmp SETVBV
; ------------------------------------------------------------------------
.code
doneirq:
ldy IRQInd+1
ldx IRQInd+2
;jmp SETVBV
; fall thru
; ------------------------------------------------------------------------
; Set deferred vertical blank interrupt
; logic copied from Atari computer ROM
SETVBV: txa
ldx #5
sta WSYNC ; waste 20 CPU cycles
@1: dex ; to allow VBLANK to happen
bne @1 ; if this is line "7C"
sta VVBLKD+1
sty VVBLKD
rts
; ------------------------------------------------------------------------
.segment "LOWCODE"
IRQStub:
cld ; Just to be sure
jsr callirq ; Call the functions
jmp IRQInd ; Jump to the saved IRQ vector
; ------------------------------------------------------------------------
.data
IRQInd: jmp $0000

View File

@@ -0,0 +1,130 @@
;
; Standard joystick driver for the Atari 5200.
;
; Christian Groessler, 2014-05-28
;
.include "zeropage.inc"
.include "joy-kernel.inc"
.include "joy-error.inc"
.include "atari5200.inc"
; ------------------------------------------------------------------------
; Header. Includes jump table
.segment "HEADER"
; Driver signature
.byte $6A, $6F, $79 ; "joy"
.byte JOY_API_VERSION ; Driver API version number
; Library reference
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $20 ; JOY_FIRE2
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
.addr UNINSTALL
.addr COUNT
.addr READJOY
.addr 0 ; IRQ entry not used
.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
ldx #0
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------
; UNINSTALL 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.
;
COUNT:
lda $FD32 ; check ROM version
cmp #$E8
bne @2port
lda #4
.byte $2C ; bit opcode, eats the next 2 bytes
@2port: lda #2
ldx #0
rts
; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A.
;
CENTER = 228 / 2
SENSIVITY = 16
READJOY:
and #3 ; put joystick number in range, just in case
tay
asl a
tax ; Joystick number * 2 (0-6) into X, index into ZP shadow registers
lda #0 ; Initialize return value
cmp TRIG0,y
bne @notrg
lda #$10 ; JOY_FIRE
; Read joystick
@notrg: ldy PADDL0,x ; get horizontal position
cpy #CENTER-SENSIVITY
bcs @chkleft
ora #4 ; JOY_LEFT
bne @updown
@chkleft:
cpy #CENTER+SENSIVITY
bcc @updown
ora #8 ; JOY_RIGHT
@updown:ldy PADDL0+1,x ; get vertical position
cpy #CENTER-SENSIVITY
bcs @chkdown
ora #1 ; JOY_UP
bne @done
@chkdown:
cpy #CENTER+SENSIVITY
bcc @done
ora #2 ; JOY_DOWN
@done: rts

View File

@@ -0,0 +1,12 @@
;
; Address of the static standard joystick driver
;
; Christian Groessler, 2014-05-12
;
; const void joy_static_stddrv[];
;
.export _joy_static_stddrv
.import _atr5200std_joy
_joy_static_stddrv := _atr5200std_joy

View File

@@ -0,0 +1,8 @@
;
; Christian Groessler, 2014-05-12
;
.export joy_libref
.import _exit
joy_libref := _exit

33
libsrc/atari5200/mul20.s Normal file
View File

@@ -0,0 +1,33 @@
;
; Christian Groessler, April 2014
;
; mul20
; multiplies A by 20 and returns result in AX
; uses tmp4
.importzp tmp4
.export mul20,loc_tmp
.proc mul20
ldx #0
stx tmp4
sta loc_tmp
asl a
rol tmp4
asl a
rol tmp4 ; val * 4
adc loc_tmp
bcc L1
inc tmp4 ; val * 5
L1: asl a
rol tmp4 ; val * 10
asl a
rol tmp4 ; val * 20
ldx tmp4
rts
.endproc
.bss
loc_tmp:.res 1

View File

@@ -0,0 +1,17 @@
;
; Christian Groessler, 01-Mar-2014
;
; void _randomize (void);
; /* Initialize the random number generator */
;
.export __randomize
.import _srand
.include "atari5200.inc"
__randomize:
ldx VCOUNT ; Use vertical line counter as high byte
lda RTCLOK+1 ; Use clock as low byte
jmp _srand ; Initialize generator

View File

@@ -0,0 +1,11 @@
; Dummy version, there is no visible cursor in the default CONIO screen
;
; 28-May-2014, Christian Groessler <chris@groessler.org>
.export setcursor
.proc setcursor
rts
.endproc

View File

@@ -0,0 +1,39 @@
;
; Ullrich von Bassewitz, 2003-08-12
;
; unsigned char __fastcall__ _sysuname (struct utsname* buf);
;
.export __sysuname, utsdata
.import utscopy
__sysuname = utscopy
;--------------------------------------------------------------------------
; Data. We define a fixed utsname struct here and just copy it.
.rodata
utsdata:
; sysname
.asciiz "cc65"
; nodename
.asciiz ""
; release
.byte ((.VERSION >> 8) & $0F) + '0'
.byte '.'
.byte ((.VERSION >> 4) & $0F) + '0'
.byte $00
; version
.byte (.VERSION & $0F) + '0'
.byte $00
; machine
.asciiz "Atari5200"

41
libsrc/atari5200/y2k.inc Normal file
View File

@@ -0,0 +1,41 @@
;-----------------------------------------------------------
; Y2K FIX by Alan Davis, Dennis Debro, and Ronen Habot
;-----------------------------------------------------------
Y2K LDY #$00 ; Copy BIOS opening screen to RAM
LDA #$FD
STA TEMPH
LDA #$58 ; Assume 2 port system
LDX $FD32
CPX #$E8 ; Is this a 4 port?
BNE Y2K0 ; Jump if not
LDA #$42 ; Yes, 4 port system
Y2K0 STA TEMPL
Y2K1 LDA (TEMPL),Y
STA $0600,Y
INY
BNE Y2K1
LDY #$50
INC TEMPH
Y2K2 LDA (TEMPL),Y
STA $0700,Y
DEY
BPL Y2K2
LDA #$D4 ; Point to copyright string
STA $0724
LDA #$BF
STA $0725
LDX #$0B ; Store NOP's @ end
LDA #$EA
Y2K3 STA $0732,X
DEX
BPL Y2K3
LDA #$60 ; Store RTS opcode @ end
STA $0750
JSR $0600 ; Show title screen
LDY #$00 ; Clear RAM from $0600-$3FFF
STY $80
LDA #$06
STA $81
JSR CLRRAM
RTS