Add mono conio files

This commit is contained in:
Karri Kaksonen 2022-04-18 11:59:06 +03:00
parent 9fecf0b2cc
commit 4fc1270110
6 changed files with 2656 additions and 0 deletions

View File

@ -0,0 +1,28 @@
;
; Groepaz/Hitmen, 19.10.2015
;
; import/overload stubs for the monochrome conio implementation
;
; mono_conio.s
.import _mono_screen
.export _screen := _mono_screen
; mono_clrscr.s
.import _mono_clrscr
.export _clrscr := _mono_clrscr
; mono_cputc.s
.import _mono_cputc
.export _cputc := _mono_cputc
; mono_font.s
.import _mono_font
.export _font := _mono_font
; mono_setcursor.s
.import mono_gotoxy
.export gotoxy := mono_gotoxy
.import _mono_gotoxy
.export _gotoxy := _mono_gotoxy

View File

@ -0,0 +1,39 @@
.include "atari7800.inc"
.export _mono_clrscr
.import _screen
.import pusha0,pushax
.include "extzp.inc"
.code
.proc _mono_clrscr
lda #<_screen
ldx #>_screen
sta ptr7800
stx ptr7800+1
ldx #screenrows
@L1: ldy #mono_charsperline
lda #0
@L2: sta (ptr7800),y
dey
bne @L2
lda ptr7800
clc
adc #mono_charsperline
bcc @L3
inc ptr7800+1
@L3: dex
bne @L1
rts
.endproc
;-------------------------------------------------------------------------------
; force the init constructor to be imported
.import mono_initconio
conio_init = mono_initconio

View File

@ -0,0 +1,227 @@
;
; 2022-04-02, Karri Kaksonen
;
; The Atari 7800 has only 4k of RAM. So for a generic conio implementation
; the best alternative is to use indirect tile mapping with a character
; frame buffer
;
.constructor mono_initconio
.include "atari7800.inc"
.include "extzp.inc"
.import _mono_font
.import _get_tv
.export _mono_screen
.export _mono_zones
.export _mono_dll
.bss
_mono_screen:
.res mono_charsperline * screenrows
;----------------------------------------------------------------------------
; Macros used to generate lists
.macro DLLentry offset, addr
.byte offset
.byte >addr
.byte <addr
.endmacro
.macro NullHeader offset, zero
.byte offset
.byte zero
.endmacro
.macro Header addr, palwidth, hpos
.byte <addr
.byte palwidth
.byte >addr
.byte hpos
.endmacro
.macro XHeader addr, flags, palwidth, hpos
.byte <addr
.byte flags
.byte >addr
.byte palwidth
.byte hpos
.endmacro
.macro TextZone row
; Text
.byte <(_mono_screen + 2 * row * charsperline)
.byte $60
.byte >(_mono_screen + 2 * row * charsperline)
.byte 12
.byte 0
.byte <(_mono_screen + 2 * row * charsperline + charsperline)
.byte $60
.byte >(_mono_screen + 2 * row * charsperline + charsperline)
.byte 12
.byte 80
; Cursor
.byte 95
.byte 0
.byte >_mono_font
.byte 0
.endmacro
;-----------------------------------------------------------------------------
; The Atari 7800 has only 4k of RAM. So for a generic conio implementation
; the best alternative is to use indirect tile mapping with a character
; frame buffer
.data
_mono_zones:
zone0: TextZone 0
nh: NullHeader 0, 0
zone1: TextZone 1
NullHeader 0, 0
zone2: TextZone 2
NullHeader 0, 0
zone3: TextZone 3
NullHeader 0, 0
zone4: TextZone 4
NullHeader 0, 0
zone5: TextZone 5
NullHeader 0, 0
zone6: TextZone 6
NullHeader 0, 0
zone7: TextZone 7
NullHeader 0, 0
zone8: TextZone 8
NullHeader 0, 0
zone9: TextZone 9
NullHeader 0, 0
zone10: TextZone 10
NullHeader 0, 0
zone11: TextZone 11
NullHeader 0, 0
zone12: TextZone 12
NullHeader 0, 0
zone13: TextZone 13
NullHeader 0, 0
zone14: TextZone 14
NullHeader 0, 0
zone15: TextZone 15
NullHeader 0, 0
zone16: TextZone 16
NullHeader 0, 0
zone17: TextZone 17
NullHeader 0, 0
zone18: TextZone 18
NullHeader 0, 0
zone19: TextZone 19
NullHeader 0, 0
zone20: TextZone 20
NullHeader 0, 0
zone21: TextZone 21
NullHeader 0, 0
zone22: TextZone 22
NullHeader 0, 0
zone23: TextZone 23
NullHeader 0, 0
zone24: TextZone 24
NullHeader 0, 0
zone25: TextZone 25
NullHeader 0, 0
zone26: TextZone 26
NullHeader 0, 0
zone27: TextZone 27
NullHeader 0, 0
_mono_dll:
PALscanlines: ; 25 lines
DLLentry 15, nh
DLLentry 8, nh
Topscanlines: ; 9 lines
DLLentry 8, nh
Displaylines:
DLLentry $80+7, zone0 ; NMI interrupt from end of prev zone
DLLentry 7, zone1
DLLentry 7, zone2
DLLentry 7, zone3
DLLentry 7, zone4
DLLentry 7, zone5
DLLentry 7, zone6
DLLentry 7, zone7
DLLentry 7, zone8
DLLentry 7, zone9
DLLentry 7, zone10
DLLentry 7, zone11
DLLentry 7, zone12
DLLentry 7, zone13
DLLentry 7, zone14
DLLentry 7, zone15
DLLentry 7, zone16
DLLentry 7, zone17
DLLentry 7, zone18
DLLentry 7, zone19
DLLentry 7, zone20
DLLentry 7, zone21
DLLentry 7, zone22
DLLentry 7, zone23
DLLentry 7, zone24
DLLentry 7, zone25
DLLentry 7, zone26
DLLentry 7, zone27
Bottomscanlines:
DLLentry $80+15, nh ; NMI interrupt at end of display
DLLentry 9, nh
DLLentry 15, nh
DLLentry 8, nh
;-----------------------------------------------------------------------------
; Set up the screen to 320a mode
;
.segment "ONCE"
CTRL_MODE160 .set 0
CTRL_MODEAC .set 3
CTRL_KANGOFF .set 0
CTRL_BCBLACK .set 0
CTRL_CHAR1B .set 0
CTRL_CHAR2B .set $10
CTRL_DMAON .set $40
CTRL_CKOFF .set 0
;-----------------------------------------------------------------------------
; Initialize the conio display lists and zones
;
.proc mono_initconio
jsr _get_tv
bne pal
lda #<Topscanlines
sta DPPL
lda #>Topscanlines
sta DPPH
jmp vblankon
pal: lda #<PALscanlines
sta DPPL
lda #>PALscanlines
sta DPPH
vblankon:
lda MSTAT
bmi vblankon
vblankoff:
lda MSTAT
bpl vblankoff
lda #>_mono_font
sta CHBASE
lda #(CTRL_MODEAC | CTRL_KANGOFF | CTRL_BCBLACK | CTRL_CHAR1B | CTRL_DMAON | CTRL_CKOFF)
sta CTRL
lda #$00 ; Black background
sta BKGRND
sta CURS_X
sta CURS_Y
lda #$0f ; White
sta P0C1
rts
.endproc

View File

@ -0,0 +1,102 @@
;
; Mark Keates, Christian Groessler, Piotr Fusik, Karri Kaksonen
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
;
.export _mono_cputc
.import _mono_gotoxy, _mono_gotox, _mono_gotoy, pusha0
.import pushax
.import _mono_screen
.include "atari7800.inc"
.include "extzp.inc"
.code
;---------------------------------------------------------------------------
; 8x16 routine
umula0:
ldy #8 ; Number of bits
lda #0
lsr ptr7800 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptrtmp
tax
lda ptrtmp+1 ; hi byte of left op
clc
adc ptr7800+1
sta ptr7800+1
txa
@L1: ror ptr7800+1
ror a
ror ptr7800
dey
bne @L0
tax
lda ptr7800 ; Load the result
rts
;-----------------------------------------------------------------------------
; Put a character on screen
;
; The code will handle newlines that wrap to start of screen
;
.proc _mono_cputc
cmp #$0A ; LF
bne @L4
@L1: lda #0 ; newline
jsr _mono_gotox
lda CURS_Y
cmp #(screenrows-1)
bne @L2
lda #0
beq @L3
@L2: clc
adc #1
@L3: jmp _mono_gotoy
@L4:
pha
lda #0
sta ptr7800+1
sta ptrtmp+1
lda CURS_Y ; Find position on screen buffer
sta ptr7800
lda #mono_charsperline
sta ptrtmp
jsr umula0
clc
adc CURS_X
bcc @L11
inx
@L11: clc
adc #<(_mono_screen)
sta ptr7800
bcc @L12
inx
@L12: txa
clc
adc #>(_mono_screen)
sta ptr7800+1
pla ; Print character on screen
ldy #0
sta (ptr7800),y
lda CURS_X ; Increment cursor
cmp #(mono_charsperline-1)
beq @L1
clc
adc #1
jmp _mono_gotox
.endproc

2052
libsrc/atari7800/mono_font.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,208 @@
;
; 2022-04-03, Karri Kaksonen
;
; setcursor (unsigned char on);
;
; The Atari 7800 does not have a hw cursor.
; This module emulates a cursor to be used with the conio
; implementation.
;
; The actual cursor display is included in the conio dll
; but every scanline has the element silenced by default
; at the end of every zone.
;
; The way the cursor works is to silence it before the cursor
; position changes and enable it afterwards.
;
; In order to get some performance we have a pointer to the
; cursor header structure. This structure is always at the
; end of the zone. So the pointer changes when CURS_Y changes.
;
; There is so many dependencies that it makes sense to
; deal with all CURS_X, CURS_Y stuff in this file and
; definitely not allow direct access to the variables.
;
.export mono_gotoxy, _mono_gotoxy, _mono_gotox, _mono_gotoy
.constructor mono_init_cursor
.interruptor mono_blink_cursor
.importzp sp
.import _mono_zones
.import cursor
.import pusha, incsp1, pusha0, pushax, popa
.include "atari7800.inc"
.include "extzp.inc"
.macpack generic
.data
;-----------------------------------------------------------------------------
; The variables used by cursor functions
;
blink_time:
.byte 140
.code
;---------------------------------------------------------------------------
; 8x16 routine
umula0:
ldy #8 ; Number of bits
lda #0
lsr ptr7800 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptrtmp
tax
lda ptrtmp+1 ; hi byte of left op
adc ptr7800+1
sta ptr7800+1
txa
@L1: ror ptr7800+1
ror a
ror ptr7800
dey
bne @L0
tax
lda ptr7800 ; Load the result
rts
;-----------------------------------------------------------------------------
; Calculate cursorzone address
; You also need to set the cursorzone to point to the correct cursor Header
; at the end of line CURS_Y.
; Offset to cursor zone 5. To next line offset 11
; cursorzone points to _mono_zones + CURS_Y * 16 + 10
; A = CURS_Y
.proc calccursorzone
sta ptr7800
lda #16
sta ptrtmp
lda #0
sta ptr7800+1
sta ptrtmp+1
jsr umula0
clc
adc #10
bcc @L1
inx
@L1: clc
adc #<_mono_zones
sta cursorzone ; calculate new cursorzone
txa
clc
adc #>_mono_zones
sta cursorzone+1
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to Y position.
; You also need to set the cursorzone to point to the correct cursor Header
; at the end of line CURS_Y.
; Offset to cursor zone 5. To next line offset 11
; cursorzone points to _mono_zones + CURS_Y * 11 + 5
;
; cursorzone[1] = 0 when not CURS_Y, 31 if CURS_Y
;
; Disable cursor
; cursorzone[1] = 0
;
; Enable cursor
; if showcursor cursorzone[1] = 31
;
.proc _mono_gotoy
pha
lda CURS_Y
jsr calccursorzone
ldy #1
lda #0
sta (cursorzone),y ; disable cursor
pla
sta CURS_Y
jsr calccursorzone
lda cursor
beq @L1
lda #31 ; enable cursor
@L1: ldy #1
sta (cursorzone),y
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to X position.
; You also need to set the hpos offset to the correct value on this line
; cursorzone[3] = 4 * CURS_X?
;
.proc _mono_gotox
sta CURS_X
ldy #3
clc
rol
rol
sta (cursorzone),y
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to desired position (X,Y)
;
.proc _mono_gotoxy
jsr _mono_gotoy
jsr popa
jsr _mono_gotox
rts
.endproc
.proc mono_gotoxy
jsr popa
jmp _mono_gotoxy
.endproc
;-----------------------------------------------------------------------------
; Initialize cursorzone at startup
; Offset to cursor zone 5.
;
.proc mono_blink_cursor
inc blink_time
bne @L3
lda #140
sta blink_time
ldy #0
lda (cursorzone),y
cmp #32
bne @L1
lda #95
bne @L2
@L1: lda #32
@L2: sta (cursorzone),y
@L3: rts
.endproc
;-----------------------------------------------------------------------------
; Initialize cursorzone at startup
; Offset to cursor zone 5.
;
.segment "ONCE"
mono_init_cursor:
lda #0
jsr calccursorzone
rts
;-----------------------------------------------------------------------------
; force the init constructor to be imported
.import mono_initconio
conio_init = mono_initconio