From 92b32d7d0ec65534602e3edd6911ed9a31b673d6 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 25 Apr 2014 03:02:44 +0200 Subject: [PATCH] atari5200 update: simple conio "hello world" works now --- asminc/atari5200.inc | 7 +-- cfg/atari5200.cfg | 2 +- libsrc/atari5200/conioscreen.s | 67 ++++++++++++++++++++++++ libsrc/atari5200/cputc.s | 95 ++++++++++++++++++++++++++++++++++ libsrc/atari5200/crt0.s | 13 ++--- libsrc/atari5200/mul20.s | 33 ++++++++++++ libsrc/atari5200/setcursor.s | 49 ++++++++++++++++++ 7 files changed, 252 insertions(+), 14 deletions(-) create mode 100644 libsrc/atari5200/conioscreen.s create mode 100644 libsrc/atari5200/cputc.s create mode 100644 libsrc/atari5200/mul20.s create mode 100644 libsrc/atari5200/setcursor.s diff --git a/asminc/atari5200.inc b/asminc/atari5200.inc index d8bf93c7c..6ae2483d2 100644 --- a/asminc/atari5200.inc +++ b/asminc/atari5200.inc @@ -55,10 +55,11 @@ PADDL5 = $16 ;POT5 " PADDL6 = $17 ;POT6 " PADDL7 = $18 ;POT7 " +; cc65 runtime zero page variables -.importzp COLCRS_5200 -.importzp ROWCRS_5200 - +COLCRS_5200 = $19 +ROWCRS_5200 = $1A +SAVMSC = $1B ; pointer to screen memory (conio) ;------------------------------------------------------------------------- ; Page #2 diff --git a/cfg/atari5200.cfg b/cfg/atari5200.cfg index 294cad26e..fb151d4ec 100644 --- a/cfg/atari5200.cfg +++ b/cfg/atari5200.cfg @@ -5,7 +5,7 @@ SYMBOLS { __RESERVED_MEMORY__: type = export, value = $0200; # space for display list and 20x24 screen buffer } MEMORY { - ZP: file = "", start = $0019, size = $00E7, define = yes; + ZP: file = "", start = $001D, size = $00E3, define = yes; RAM: file = "", start = $021C, size = $4000 - __STACKSIZE__ - __RESERVED_MEMORY__ - $021C, define = yes; ROM: file = %O, start = $C000 - __CARTSIZE__, size = __CARTSIZE__ - $18, define = yes, fill = yes, fillval = $FF; CARTNAME: file = %O, start = $BFE8, size = $0014 fill = yes, fillval = $40; diff --git a/libsrc/atari5200/conioscreen.s b/libsrc/atari5200/conioscreen.s new file mode 100644 index 000000000..c9d95aa51 --- /dev/null +++ b/libsrc/atari5200/conioscreen.s @@ -0,0 +1,67 @@ + + .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+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 display list + + 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 diff --git a/libsrc/atari5200/cputc.s b/libsrc/atari5200/cputc.s new file mode 100644 index 000000000..26527535d --- /dev/null +++ b/libsrc/atari5200/cputc.s @@ -0,0 +1,95 @@ +; +; 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 #40 + 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 + +; turn off cursor, update screen, turn on cursor +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 + diff --git a/libsrc/atari5200/crt0.s b/libsrc/atari5200/crt0.s index 56b58a541..a62d69703 100644 --- a/libsrc/atari5200/crt0.s +++ b/libsrc/atari5200/crt0.s @@ -1,7 +1,7 @@ ; ; Startup code for cc65 (Atari5200 version) ; -; by Christian Groessler (chris@groessler.org), 2014 +; Christian Groessler (chris@groessler.org), 2014 ; .export _exit, start @@ -15,12 +15,6 @@ .include "zeropage.inc" .include "atari5200.inc" - -; ------------------------------------------------------------------------ -; Place the startup code in a special segment. - -.segment "STARTUP" - start: ; Clear the BSS data @@ -49,7 +43,6 @@ start: _exit: jsr donelib ; Run module destructors -; Reset the NES - - jmp start +; A 5200 program isn't supposed to exit. +halt: jmp halt diff --git a/libsrc/atari5200/mul20.s b/libsrc/atari5200/mul20.s new file mode 100644 index 000000000..fc67b34e4 --- /dev/null +++ b/libsrc/atari5200/mul20.s @@ -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 diff --git a/libsrc/atari5200/setcursor.s b/libsrc/atari5200/setcursor.s new file mode 100644 index 000000000..00195f1cf --- /dev/null +++ b/libsrc/atari5200/setcursor.s @@ -0,0 +1,49 @@ + + + .include "atari5200.inc" + .export setcursor + .import cursor ; from conio/_cursor.s + + + +.proc setcursor + + rts + +.if 0 + ldy #0 + + lda ROWCRS_5200 + jsr mul20 + clc +; adc SAVMSC ; add start of screen memory +; sta OLDADR + txa +; adc SAVMSC+1 +; sta OLDADR+1 + lda COLCRS_5200 +; adc OLDADR +; sta OLDADR + bcc nc +; inc OLDADR+1 +nc:;;; lda (OLDADR),y +; sta OLDCHR + + ldx cursor ; current cursor setting as requested by the user + beq off + ldx #0 + beq cont + +off: inx +cont:;;; stx CRSINH ; update system variable + + beq turnon + and #$7f ; clear high bit / inverse flag +finish: ;;;sta (OLDADR),y ; update on-screen display + rts + +turnon: ora #$80 ; set high bit / inverse flag + bne finish +.endif + +.endproc -- 2.39.2