diff --git a/libsrc/c64/extra/soft80mono.s b/libsrc/c64/extra/soft80mono.s new file mode 100644 index 000000000..f91f4a76a --- /dev/null +++ b/libsrc/c64/extra/soft80mono.s @@ -0,0 +1,55 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; import/overload stubs for the monochrome soft80 implementation +; +; - optimized for size, almost 1k smaller footprint than the full color version +; - textcolor() sets one common text color for the whole screen +; + .include "../soft80.inc" + + ; soft80mono_cgetc.s + .import soft80mono_cgetc + .export _cgetc := soft80mono_cgetc ; cgetc.s + + ; soft80mono_color.s + .import soft80mono_textcolor + .import soft80mono_bgcolor + .export _textcolor := soft80mono_textcolor ; color.s + .export _bgcolor := soft80mono_bgcolor ; color.s + + ; soft80mono_cputc.s + .import soft80mono_cputc + .import soft80mono_cputcxy + .import soft80mono_cputdirect + .import soft80mono_putchar + .import soft80mono_newline + .import soft80mono_plot + .export _cputc := soft80mono_cputc ; cputc.s + .export _cputcxy := soft80mono_cputcxy ; cputc.s + .export cputdirect := soft80mono_cputdirect ; cputc.s + .export putchar := soft80mono_putchar ; cputc.s + .export newline := soft80mono_newline ; cputc.s + .export plot := soft80mono_plot ; cputc.s + + ; soft80mono_kclrscr.s + .import soft80mono_kclrscr + .export _clrscr := soft80mono_kclrscr ; clrscr.s + .export CLRSCR := soft80mono_kclrscr ; kernal func (c64.inc) + + ; soft80mono_kplot.s + .import soft80mono_kplot + .export PLOT := soft80mono_kplot ; kplot.s + + ; soft80_kscreen.s + .import soft80_screensize + .export screensize := soft80_screensize ; _scrsize.s + .export SCREEN := soft80_screensize ; kernal func (kernal.s) + + ; VIC sprite data for the mouse pointer + .export mcb_spritememory := soft80_spriteblock + .export mcb_spritepointer := (soft80_vram + $03F8) + + ; Chars used by chline () and cvline () + .exportzp chlinechar = CH_HLINE + .exportzp cvlinechar = CH_VLINE diff --git a/libsrc/c64/soft80mono_cgetc.s b/libsrc/c64/soft80mono_cgetc.s new file mode 100644 index 000000000..d99dc7775 --- /dev/null +++ b/libsrc/c64/soft80mono_cgetc.s @@ -0,0 +1,66 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; char cgetc (void); +; + + .export soft80mono_cgetc + .import soft80mono_internal_cellcolor, soft80mono_internal_cursorxlsb + .import soft80mono_internal_nibble + .import cursor + .importzp tmp1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_cgetc: + lda KEY_COUNT ; Get number of characters + bne @L3 ; Jump if there are already chars waiting + + jsr invertcursor ; set cursor on or off accordingly + +@L1: lda KEY_COUNT ; wait for key + beq @L1 + + jsr invertcursor ; set cursor on or off accordingly + +@L3: jsr KBDREAD ; Read char and return in A + ldx #0 + rts + +; Switch the cursor on or off (invert) + +invertcursor: + lda cursor + bne @invert + rts +@invert: + + sei + lda $01 ; enable RAM under I/O + pha + lda #$34 + sta $01 + + ldy #$00 + ldx soft80mono_internal_cursorxlsb +@lp1: + lda (SCREEN_PTR),y + eor soft80mono_internal_nibble,x + sta (SCREEN_PTR),y + iny + cpy #8 + bne @lp1 + + pla + sta $01 ; enable I/O + cli + rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init diff --git a/libsrc/c64/soft80mono_color.s b/libsrc/c64/soft80mono_color.s new file mode 100644 index 000000000..aa24957d5 --- /dev/null +++ b/libsrc/c64/soft80mono_color.s @@ -0,0 +1,65 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + .export soft80mono_textcolor, soft80mono_bgcolor + .import soft80mono_internal_cellcolor, soft80mono_internal_bgcolor + + .importzp tmp1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_textcolor: + ldx CHARCOLOR ; get old value + stx tmp1 ; save old value + sta CHARCOLOR ; set new value + +mkcharcolor: + lda soft80mono_internal_bgcolor + asl a + asl a + asl a + asl a + ora CHARCOLOR + sta soft80mono_internal_cellcolor ; text/bg combo for new chars + + sei + ldy $01 + lda #$34 ; enable RAM under I/O + sta $01 + + lda soft80mono_internal_cellcolor + ; clear loop for vram + ldx #$00 +@lp1: + sta soft80_vram,x + sta soft80_vram+$100,x + sta soft80_vram+$200,x + sta soft80_vram+$2e8,x + inx + bne @lp1 + + sty $01 + cli + + lda tmp1 ; get old value + rts + +soft80mono_bgcolor: + ldx soft80mono_internal_bgcolor ; get old value + stx tmp1 ; save old value + sta soft80mono_internal_bgcolor ; set new value + + jmp mkcharcolor + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init diff --git a/libsrc/c64/soft80mono_conio.s b/libsrc/c64/soft80mono_conio.s new file mode 100644 index 000000000..759b280c6 --- /dev/null +++ b/libsrc/c64/soft80mono_conio.s @@ -0,0 +1,168 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; Low level init code for the monochrome soft80 screen output/console input +; + + .constructor soft80mono_init, 8 + .destructor soft80mono_shutdown + + .import soft80mono_kclrscr, soft80_charset + .export soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .export soft80mono_internal_cursorxlsb + .export soft80mono_internal_nibble + + .importzp ptr1, ptr2, ptr3 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_init: + lda soft80mono_first_init + bne @skp + jsr firstinit +@skp: + ; the "color voodoo" in other parts of the code relies on the vram and + ; colorram being set up as expected, which is why we cant use the + ; _bgcolor and _textcolor functions here. + + lda CHARCOLOR ; use current textcolor + and #$0f ; make sure the upper nibble is 0s + sta CHARCOLOR + + lda VIC_BG_COLOR0 ; use current bgcolor + and #$0f + sta soft80mono_internal_bgcolor + asl a + asl a + asl a + asl a + ora CHARCOLOR + sta soft80mono_internal_cellcolor + + lda #$3b + sta VIC_CTRL1 + lda #$00 + sta CIA2_PRA + lda #$68 + sta VIC_VIDEO_ADR + lda #$c8 + sta VIC_CTRL2 + + jmp soft80mono_kclrscr + +soft80mono_shutdown: + lda #$1b + sta VIC_CTRL1 + lda #$03 + sta CIA2_PRA + lda #$15 + sta VIC_VIDEO_ADR + rts + + .segment "INIT" +firstinit: + ; copy charset to RAM under I/O + sei + lda $01 + pha + lda #$34 + sta $01 + + inc soft80mono_first_init + + lda #>soft80_charset + sta ptr1+1 + lda #soft80_lo_charset + sta ptr2+1 + lda #soft80_hi_charset + sta ptr3+1 + lda #((col/2)*8) + .endrepeat +soft80_vramlo_data: + .repeat 25,row + .byte <(soft80_vram+(row*40)) + .endrepeat + .byte 0,0,0,0,0,0,0 ; padding to next page +soft80_vramhi_data: + .repeat 25,row + .byte >(soft80_vram+(row*40)) + .endrepeat +soft80_bitmapylo_data: + .repeat 25,row + .byte <(soft80_bitmap+(row*40*8)) + .endrepeat +soft80_bitmapyhi_data: + .repeat 25,row + .byte >(soft80_bitmap+(row*40*8)) + .endrepeat + +soft80_tables_data_end: + +;------------------------------------------------------------------------------- + .segment "INITBSS" +soft80mono_internal_cellcolor: + .res 1 +soft80mono_internal_bgcolor: + .res 1 +soft80mono_internal_cursorxlsb: + .res 1 + + .data +soft80mono_first_init: + .byte 0 ; flag to check first init, this really must be in .data + + .rodata +soft80mono_internal_nibble: + .byte $f0, $0f + diff --git a/libsrc/c64/soft80mono_cputc.s b/libsrc/c64/soft80mono_cputc.s new file mode 100644 index 000000000..c89362cb5 --- /dev/null +++ b/libsrc/c64/soft80mono_cputc.s @@ -0,0 +1,205 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export soft80mono_cputcxy, soft80mono_cputc + .export soft80mono_cputdirect, soft80mono_putchar + .export soft80mono_newline, soft80mono_plot + + .import popa, _gotoxy + + .import soft80mono_kplot + .import soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .import soft80mono_internal_cursorxlsb, soft80mono_internal_nibble + + .importzp tmp4, tmp3, ptr2 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +soft80mono_cputc: + cmp #$0A ; CR? + bne L1 + + lda #0 + sta CURS_X + + ; Set cursor position, calculate RAM pointers +soft80mono_plot: + ldx CURS_Y + ldy CURS_X + clc + jmp soft80mono_kplot ; Set the new cursor + +L1: cmp #$0D ; LF? + beq soft80mono_newline ; Recalculate pointers + + ; shortcut for codes < $80 ... codes $20-$7f can be printed directly, + ; codes $00-$1f are control codes which are not printable and thus may + ; give undefined result. + tay + bpl @L10 + + ; codes $80-$ff must get converted like this: + ; $80-$9f -> dont care (control codes) + ; $a0-$bf -> $00-$1f + ; $c0-$df -> $60-$7f + ; $e0-$ff -> $00-$1f + + ora #%01000000 ; $40 + clc + adc #%00100000 ; $20 + and #%01111111 ; $7f +@L10: + + ; entry point for direct output of a character. the value passed in + ; akku must match the offset in the charset. + ; - the following may not modify tmp1 +soft80mono_cputdirect: + jsr soft80mono_putchar ; Write the character to the screen + + ; Advance cursor position + iny ; contains CURS_X + cpy #charsperline + beq @L3 + + sty CURS_X + tya + and #$01 + sta soft80mono_internal_cursorxlsb + bne @L4 + + lda SCREEN_PTR + clc + adc #8 + sta SCREEN_PTR + bcc @L4 + inc SCREEN_PTR+1 +@L4: + rts +@L3: + inc CURS_Y ; new line + ldy #0 ; + cr + sty CURS_X + jmp soft80mono_plot + + ; - the following may not modify tmp1 +soft80mono_newline: + + lda SCREEN_PTR + clc + adc #<(40*8) + sta SCREEN_PTR + + lda SCREEN_PTR+1 + adc #>(40*8) + sta SCREEN_PTR+1 + + inc CURS_Y + rts + +;------------------------------------------------------------------------------- +; output one character in internal encoding without advancing cursor position +; generic entry point +; +; - the following may not modify tmp1 +; in: A: charcode +; out: Y: CURS_X +; +soft80mono_putchar: + sta tmp3 ; save charcode + + sei + lda $01 + pha + lda #$34 + sta $01 ; enable RAM under I/O + + ldy #$00 ; will be $00 from now on + + ldx soft80mono_internal_cursorxlsb + lda chardatal,x + clc + adc tmp3 + sta ptr2 + lda chardatah,x + adc #0 + sta ptr2+1 + + lda RVS + bne draw_charinvers + + lda nibble,x + sta tmp3 + + ;ldy #0 ; is still $00 +@lp1: + lda (SCREEN_PTR),y + and tmp3 + ora (ptr2),y + sta (SCREEN_PTR),y + clc + lda ptr2 + adc #$7f + sta ptr2 + bcc @sk1 + inc ptr2+1 +@sk1: + iny + cpy #8 + bne @lp1 + +draw_back: + pla + sta $01 + cli + + ldy CURS_X + rts + +; output inverted character +draw_charinvers: + lda soft80mono_internal_nibble,x + sta tmp3 + + ;ldy #0 ; is still $00 +@lp1: + lda (SCREEN_PTR),y + ora tmp3 + eor (ptr2),y + sta (SCREEN_PTR),y + clc + lda ptr2 + adc #$7f + sta ptr2 + bcc @sk1 + inc ptr2+1 +@sk1: + iny + cpy #8 + bne @lp1 + jmp draw_back + + .rodata +chardatal: + .byte soft80_hi_charset + .byte >soft80_lo_charset +nibble: + .byte $0f, $f0 + diff --git a/libsrc/c64/soft80mono_kclrscr.s b/libsrc/c64/soft80mono_kclrscr.s new file mode 100644 index 000000000..99243c699 --- /dev/null +++ b/libsrc/c64/soft80mono_kclrscr.s @@ -0,0 +1,63 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; lowlevel kclrscr for the monochrome soft80 implementation +; + + .export soft80mono_kclrscr + .import soft80mono_kplot + .import soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .importzp ptr1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_kclrscr: + + lda #soft80_bitmap + sta ptr1+1 + + lda #$ff + + ldx #$1f +@lp2: + ldy #0 +@lp1: + sta (ptr1),y + iny + bne @lp1 + inc ptr1+1 + dex + bne @lp2 + + ;ldx #$00 +@lp3: + sta soft80_bitmap+$1e40,x + inx + bne @lp3 + + sei + ldy $01 + lda #$34 ; enable RAM under I/O + sta $01 + + lda soft80mono_internal_cellcolor + ; clear loop for vram + ;ldx #$00 +@lp4: + sta soft80_vram,x + sta soft80_vram+$100,x + sta soft80_vram+$200,x + sta soft80_vram+$2e8,x + inx + bne @lp4 + + sty $01 + cli + + ldx #0 + ldy #0 + clc + jmp soft80mono_kplot diff --git a/libsrc/c64/soft80mono_kplot.s b/libsrc/c64/soft80mono_kplot.s new file mode 100644 index 000000000..b987924f3 --- /dev/null +++ b/libsrc/c64/soft80mono_kplot.s @@ -0,0 +1,52 @@ + +; +; Groepaz/Hitmen, 19.10.2015 +; +; lowlevel kplot function for the monochrome soft80 implementation +; + + .export soft80mono_kplot + .import soft80mono_internal_cursorxlsb + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_kplot: + bcs @getpos + + stx CURS_Y + sty CURS_X + + sei + lda $01 + pha + lda #$34 ; enable RAM under I/O + sta $01 + + ; calc pointer to bitmap + lda soft80_bitmapylo,x + clc + adc soft80_bitmapxlo,y + sta SCREEN_PTR + lda soft80_bitmapyhi,x + adc soft80_bitmapxhi,y + sta SCREEN_PTR+1 + + tya + and #1 + sta soft80mono_internal_cursorxlsb + + pla + sta $01 + cli + +@getpos: + ldx CURS_Y + ldy CURS_X + rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init