]> git.sur5r.net Git - cc65/commitdiff
atari5200 update: simple conio "hello world" works now
authorChristian Groessler <chris@groessler.org>
Fri, 25 Apr 2014 01:02:44 +0000 (03:02 +0200)
committerChristian Groessler <chris@groessler.org>
Fri, 25 Apr 2014 01:02:44 +0000 (03:02 +0200)
asminc/atari5200.inc
cfg/atari5200.cfg
libsrc/atari5200/conioscreen.s [new file with mode: 0644]
libsrc/atari5200/cputc.s [new file with mode: 0644]
libsrc/atari5200/crt0.s
libsrc/atari5200/mul20.s [new file with mode: 0644]
libsrc/atari5200/setcursor.s [new file with mode: 0644]

index d8bf93c7ca2b630aa180195ded79785c7ef4064d..6ae2483d27641587914d649514d6ec3b913631ed 100644 (file)
@@ -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
index 294cad26ea01ca2dea4fbb7c4e5fdd66732bb6d2..fb151d4ec47d98d155e7fc939cdff036d381e663 100644 (file)
@@ -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 (file)
index 0000000..c9d95aa
--- /dev/null
@@ -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
+               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     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
diff --git a/libsrc/atari5200/cputc.s b/libsrc/atari5200/cputc.s
new file mode 100644 (file)
index 0000000..2652753
--- /dev/null
@@ -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
+
index 56b58a541928f10fdb99871c60fd499cc7201723..a62d69703cdc73da4fed22ecf151c65522928ca4 100644 (file)
@@ -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
         .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 (file)
index 0000000..fc67b34
--- /dev/null
@@ -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 (file)
index 0000000..00195f1
--- /dev/null
@@ -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