Added simple kernel functions

This commit is contained in:
0xMAC8205 2023-11-03 01:08:40 +01:00
parent c1f1b8c064
commit 46d86823eb
9 changed files with 271 additions and 20 deletions

View File

@ -28,6 +28,8 @@ Hardware.s
+- vram_dump +- vram_dump
Int.s Int.s
|
+- int16_add_byte
Irq.s Irq.s
| |

BIN
a.out

Binary file not shown.

32
main.s
View File

@ -44,14 +44,38 @@ reset: sei
stz system_register stz system_register
stz soft_system_register stz soft_system_register
jsr video_writeline_static ;jsr video_writeline_static
.string "Hello World" ;.string "Hello World"
jsr video_clear
jsr kernel_init ldx #<charset
ldy #>charset
jsr video_load_font
lda #$f0
jsr irq_init
loop: jmp loop stz k0
lda #$00
tax
tay
lp:
lda k0
jsr vram_write
inc k0
inx
cpx #$10
bne lp
ldx #$00
iny
cpy #$10
bne lp
loop:
jmp loop
irq_jump: jmp (irq_vector) irq_jump: jmp (irq_vector)

View File

@ -6,8 +6,4 @@
.include "src/kernel/event_handler.s" .include "src/kernel/event_handler.s"
.include "src/kernel/memory_manager.s" .include "src/kernel/memory_manager.s"
.include "src/kernel/hardware.s" .include "src/kernel/hardware.s"
kernel_init:
rts

View File

@ -34,11 +34,13 @@ vram_write_color:
; Output: (none) ; Output: (none)
; I'm deliberately NOT using Kernel Stack here, ; I'm deliberately NOT using the Kernel Stack here,
; for more speed and efficiency and because It's just one Byte ; for more speed and efficiency and because it's just two Bytes ;)
phx ; Push X to Stack
pha ; Push A to Stack pha ; Push A to Stack
txa ; Transfer X to A for Math txa ; Transfer X to A for Math
clc
adc #$40 ; Add #$40 (Color Range) adc #$40 ; Add #$40 (Color Range)
plx ; Pop Stack to X plx ; Pop Stack to X
@ -51,6 +53,8 @@ vram_write_color:
nop nop
nop nop
sta vidx ; Sets Read Mode sta vidx ; Sets Read Mode
txa
plx
rts rts

View File

@ -0,0 +1,50 @@
int16_add_byte:
; Int16 add Int8
; Input:
; A <= Least significant Byte
; X <= Most sifnificant Byte
; Y <= Byte to add
; Output:
; A <= Least significant Byte
; X <= Most significant Byte
clc
sty k0
adc k0
bvc int16_add_byte_return
inx
int16_add_byte_return:
rts
int16_increment_pointer:
; Int16 Increment from Pointer
; Input:
; X => LOW Pointer Byte
; Y => HIGH Pointer Byte
; Output: (none)
rts
int16_increment:
; Int16 Increment
; Input:
; X => LSB -byte
; Y => MSB -byte
; Output:
; X <= LSB -byte
; Y <= MSB -byte
clc
inx
bcc int16_increment_return
iny
int16_increment_return:
rts

View File

@ -8,13 +8,12 @@ irq_init:
; Output: (none) ; Output: (none)
sta t1ch ldx #$40
stx acr
lda #$40
sta acr
stz t1cl stz t1cl
lda #$00 sta t1ch
sta ier ldx #$c0
stx ier
cli cli
rts rts
@ -35,11 +34,25 @@ irq:
sty irq_y sty irq_y
jsr keyboard_scan
phx
phy
ldx #$11
ldy #$11
jsr vram_write
pla
inx
jsr vram_write
pla
inx
jsr vram_write
bit t1cl ; "Ping" VIA Timer, to trigger Restart bit t1cl ; "Ping" VIA Timer, to trigger Restart
lda irq_a ; Restore A, X, Y and Processor Status lda irq_a ; Restore A, X, Y and Processor Status
ldx irq_x ldx irq_x
ldy irq_y ldy irq_y
plp plp
rti rti

View File

@ -11,6 +11,65 @@ keyboard_scan:
; Y <= Arrow Keys ; Y <= Arrow Keys
rts
lda soft_system_register
and #$f8
sta soft_system_register
sta system_register
ldy #$00 ; Result Index
ldx #$00 ; Row Counter
keyboard_scan_load:
lda #$fe ; Bit shifter
keyboard_scan_loop:
cmp keyboard_port
beq keyboard_scan_return
iny
rol
cmp #$fe
bne keyboard_scan_loop
inx
cpx #$08 ; Checking if Counted to 7
beq keyboard_scan_return
inc soft_system_register
lda soft_system_register
sta system_register
jmp keyboard_scan_load
keyboard_scan_return:
sty k0
lda soft_system_register
ora #$05
sta system_register
lda keyboard_port
tax
and #$0f
tay ; => Arrow Keys
txa
rol
rol
rol
rol
and #$07
tax ; => Modifier Keys
lda k0 ; => Scancode
rts rts
keyboard_translate: keyboard_translate:
@ -39,4 +98,8 @@ keyboard_format:
; A <= ASCII Char ; A <= ASCII Char
rts rts
keyboard_ascii_lookup:
.byte $80 ; bla bla bla

View File

@ -10,6 +10,56 @@ video_write:
; Output: (none) ; Output: (none)
stx z0
sty z1
; y => counter
; x => X Coords
; K0 => Y Coords
video_write_loop:
lda (z0), y
iny
cmp #$00
beq video_write_return
cpy #$00
beq video_write_return
phy
lda #$30
cmp cursor_x
bcc video_write_skip_overflow
stz cursor_x
inc cursor_y
lda #$20
cmp cursor_y
bcc video_write_skip_overflow
lda #$00
jsr video_scroll
lda #$1f
sta cursor_y
video_write_skip_overflow:
ldx cursor_x
ldy cursor_y
jsr vram_write
; cursor checking bla bla
inc cursor_x
ply
jmp video_write_loop
video_write_return:
; calc new address and put into xy
lda z0
ldx z1
jsr int16_add_byte
rts rts
@ -21,6 +71,13 @@ video_write_static:
; Input: (none) ; Input: (none)
; Output: (none) ; Output: (none)
plx
ply
jsr video_write
; if return right
phy
phx
rts rts
@ -35,6 +92,8 @@ video_writeline:
; Output: (none) ; Output: (none)
jsr video_write
jsr video_return ; or new video_newline
rts rts
@ -176,8 +235,27 @@ video_scroll:
video_clear: video_clear:
; Video Clear ; Video Clear
; Clears the Screen blank, with the normal Color ; Clears the Screen blank, with the normal Color and #$20 Chars
; Input: (none)
; Output: (none)
ldx #$00
ldy #$00
video_clear_loop:
lda #$20
jsr vram_write
lda color
jsr vram_write_color
inx
cpx #$30
bne video_clear_loop
ldx #$00
iny
cpy #$00
bne video_clear_loop
rts rts
@ -213,5 +291,26 @@ video_load_font:
; Output: (none) ; Output: (none)
stx z0
sty z1
ldx #$78
ldy #$00
video_load_font_loop:
lda (z0)
jsr vram_write
inx
inc z0
bne video_load_font_check
inc z1
video_load_font_check:
cpx #$80
bne video_load_font_loop
ldx #$78
iny
cpy #$00
bne video_load_font_loop
rts rts