From be8ae80aea3e0f6223ca2b201f6b8aecb738ce69 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 11 Mar 2016 06:58:06 -0500 Subject: preliminary work for 5200 port --- crt0_5200.s | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 crt0_5200.s (limited to 'crt0_5200.s') diff --git a/crt0_5200.s b/crt0_5200.s new file mode 100644 index 0000000..5210ec1 --- /dev/null +++ b/crt0_5200.s @@ -0,0 +1,183 @@ +; +; Startup code for cc65 (Atari5200 version) +; +; Christian Groessler (chris@groessler.org), 2014 + +; modified for taipan, to work as a diagnostic cart. +; contains code adapted from the 5200 OS ROM. + + .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 of (slightly modified) OS ROM code. the OS calls us with +;;; interrupts disabled, decimal mode cleared, with the stack pointer +;;; set to $FF. Since this is a diagnostic cart, we have to init the +;;; hardware and set up the interrupt vector table at $0200 (the OS +;;; doesn't do it for us, like it would for a non-diag cart). + +;;; This code is based on Dan Boris's commented disassembly of the 4-port +;;; 5200 BIOS, retrieved from . + +;;; I've copied just the initialization code, minus the logo/copyright +;;; screen, and modified it to work with either OS revision. + +;;; Everything I've read tells me that the 4-port OS will work on a 2-port +;;; machine (the hardware changes don't break compatibility), so the code +;;; here comes from the 4-port OS. + +; I've gone to a lot of trouble to get the vectors and display list +; set up correctly for either ROM revision... but the display list, at +; least, was really a waste of time: conio is going to set up a GR.1 +; display list... at least until I modify it to use GR.0 instead. + +start: + ldx #0 + txa +@clrloop: + sta POKEY,x ;Clear POKEY registers + sta GTIA,x ;Clear GTIA registers + sta ANTIC,x ;Clear ANTIC registers + sta $00,x ;Clear zero page + inx + bne @clrloop + lda #$F8 + sta CHBASE ;Set Character base to $F800 + +; determine which OS revision we're running under. This affects +; the locations of the vector table and display list in the ROM, +; and is probably the reason a few published 5200 games are +; incompatible with the Rev A ROM. +; rev A has $07 at $fee5, original OS has $61. If there are other +; OS revisions out there in the wild, this code will likely fail +; on them. + + lda #$fe + sta $fb +; sta $fd +; sta $ff + lda $fee5 + cmp #$07 + beq @rev_a + + ; set up $fa to point to vector table, + ; $fc to point to display list start, + ; $fe to point to DL end. + + ; old OS: + lda #$95 + sta $fa +; lda #$c8 +; sta $fc +; lda #$cf +; sta $fe + bne @copy_vectors + +@rev_a: + lda #$ab + sta $fa +; lda #$de +; sta $fc +; lda #$e5 +; sta $fe + +@copy_vectors: + ldy #$0B +@cploop: + lda ($fa),y + sta VIMIRQ,y ;Copy vectors to vector table + dey + bpl @cploop + + lda #$3C ;Set pointer to $3C00 + sta $12 + lda #$00 + sta $11 + + ldx #$0C + tay +@vecloop: + sta ($11),y + dey + bne @vecloop + dec $12 + dex + bpl @vecloop + +;;; taipan doesn't need the OS-provided display list. +;;; conio init will set up a GR.1 DL (at least, until +;;; I modify it to the GR.0 that taipan needs) +;Build display list +; lda #$0D ;Antic mode 13 +; ldx #$4D +;@dl13loop: +; sta $2007,x ;write to display list +; dex +; bpl @dl13loop +; +; ldy #$06 ;Copy start of display list +;@dlloop: +; lda ($fc),y +; sta $2000,y +; dey +; bpl @dlloop +; +; ldy #$04 ;Copy end of display list +;@dlendloop: +; lda ($fe),y +; sta $2055,y +; dey +; bpl @dlendloop +; +; lda #$00 ;Set Display List pointer to $2000 +; sta $05 +; lda #$20 +; sta $06 + + lda #$22 ;Set DMACTL, dlist on/normal background + sta SDMCTL + + lda #$C0 + sta NMIEN ;Enable DLI and VBI + lda #$02 + sta SKCTL ;Enable Keyboard scanning + + .out .sprintf("%d bytes", * - start) +;;; end of OS ROM code, rest of file is standard 5200 crt0.s. + +; Clear the BSS data. + + jsr zerobss + +; Initialize the data. + jsr copydata + +; Set up 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 the module constructors. + + jsr initlib + +; Push the command-line arguments; and, call main(). + + jsr callmain + +; Call the 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 -- cgit v1.2.3