Change 4 spaces indenting to 8 and add string for emacs to understand indenting rules

This commit is contained in:
hugova 2025-03-09 23:43:59 +01:00
parent 36610e7df8
commit a617d91183
14 changed files with 501 additions and 481 deletions

View file

@ -7,6 +7,7 @@ in terminal run
``` ```
## Debug ## Debug
Vice --> Activate Monitor Vice --> Activate Monitor
program currently start att $080D
## Chitty endian ## Chitty endian
2 bits 00 88 --> real world 8800 2 bits 00 88 --> real world 8800
@ -23,8 +24,6 @@ Vice --> Activate Monitor
[good (expansive)](https://www.masswerk.at/6502/6502_instruction_set.html#CLD) [good (expansive)](https://www.masswerk.at/6502/6502_instruction_set.html#CLD)
[wikipedia (minimalistic)](https://en.wikibooks.org/wiki/6502_Assembly) [wikipedia (minimalistic)](https://en.wikibooks.org/wiki/6502_Assembly)
### sprites ### sprites
[sprite](https://www.c64-wiki.com/wiki/Sprite#Sprite_priority) [sprite](https://www.c64-wiki.com/wiki/Sprite#Sprite_priority)
@ -38,13 +37,10 @@ Vice --> Activate Monitor
### Holding hand instructions :) ### Holding hand instructions :)
[codeburst hard asembly code](https://codeburst.io/lets-write-some-harder-assembly-language-code-c7860dcceba) [codeburst hard asembly code](https://codeburst.io/lets-write-some-harder-assembly-language-code-c7860dcceba)
[flag intro](http://www.6502.org/tutorials/vflag.html) [flag intro](http://www.6502.org/tutorials/vflag.html)
## Basic ## Basic
[peek and poke](https://en.wikipedia.org/wiki/PEEK_and_POKE) [peek and poke](https://en.wikipedia.org/wiki/PEEK_and_POKE)
# Cool unexplored tools # Cool unexplored tools
[text](https://style64.org/cbmdisk/documentation/) [text](https://style64.org/cbmdisk/documentation/)

View file

@ -1,9 +1,15 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; A file containing 16-bit macro arithmatic.
;; You may add ,! ass a 5:th parameter to skipp flagg clearing.
;; This will make it run faster but will have unintended behavior.
;; Can use A as b_low! ;;Se below for some fast 16bit logic
;; And X or Y is b_hi ;;http://6502.org/tutorials/compare_beyond.html
;; Can add ", !" to the end for it to run faster but C=0 is not garantied!
.macro Add_16 a_low, a_hi, b_low, b_hi, fast_unsafe ; a = a + b ;; Addition uses the A register
;; a = a + b
.macro Add_16 a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast ;; IF to run it fast
.ifblank fast_unsafe .ifblank fast_unsafe
CLC CLC
@ -16,8 +22,10 @@
STA a_hi STA a_hi
.endmacro .endmacro
; Untested! ;; Untested!
.macro Add_16_AX low, hi, fast_unsafe; , A, X ;; Addition uses the A register
;; a = a + b. b_low = A, b_hi = X
.macro Add_16_AX low, hi, fast_unsafe
;; IF to run it fast ;; IF to run it fast
.ifblank fast_unsafe .ifblank fast_unsafe
CLC CLC
@ -29,20 +37,25 @@
STA hi STA hi
.endmacro .endmacro
.macro Sub_16 a_low, a_hi, b_low, b_hi, fast_unsafe ; a = a - b ;; Subtraction uses the A register
;; a = a - b
.macro Sub_16 a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe .ifblank fast_unsafe
SEC SEC
.endif .endif
LDA a_low LDA a_low
SBC b_low SBC b_low
STA a_low STA a_low
LDA a_hi LDA a_hi
SBC b_hi SBC b_hi
STA a_hi STA a_hi
.endmacro .endmacro
;;Untested ;; Untested
.macro Sub_16_AX low, hi, fast_unsafe; , A, X ;; Subtraction uses the A register
;; a = a - b. b_low = A, b_hi = X
.macro Sub_16_AX low, hi, fast_unsafe
;; IF to run it fast ;; IF to run it fast
.ifblank fast_unsafe .ifblank fast_unsafe
SEC SEC
@ -54,7 +67,9 @@
STA hi STA hi
.endmacro .endmacro
.macro mult_16 low_, hi_, fast_unsafe ; [low, hi] = [low, hi]*2 ;; Multiplication of 2
;; a = a*2
.macro mult_16 low_, hi_, fast_unsafe
;; IF to run it fast ;; IF to run it fast
.ifblank fast_unsafe .ifblank fast_unsafe
CLC CLC
@ -62,18 +77,16 @@
ROL low_ ROL low_
ROL hi_ ROL hi_
.endmacro .endmacro
;;Se below for some fast 16bit logic
;;http://6502.org/tutorials/compare_beyond.html
;; exampel 4.1.1 ;;Larger then operation, uses the A register
;;Larger then operation. IF a < b then jump to label ;;IF a < b then: jump to label
.macro Lag_16 a_low, a_hi, b_low, b_hi, label ; [low, hi] = [low, hi]*2 .macro Lag_16 a_low, a_hi, b_low, b_hi, label ; [low, hi] = [low, hi]*2
LDA a_hi ; compare high bytes LDA a_hi
CMP b_hi CMP b_hi
BCC label ; if NUM1H < NUM2H then NUM1 < NUM2 BCC label
BNE LABEL ; if NUM1H <> NUM2H then NUM1 > NUM2 (so NUM1 >= NUM2) BNE LABEL
LDA a_low ; compare low bytes LDA a_low
CMP b_low CMP b_low
BCC label ; if NUM1L < NUM2L then NUM1 < NUM2 BCC label
LABEL: LABEL:
.endmacro .endmacro

View file

@ -1,26 +1,34 @@
;; Max 1.5s eller 0.9s vet ej villken ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; skriv time_start .. kod .. time_stop
;; och läs värdet i f1 ;; Max 0.9s
;; Exempel i kod:
;;
;; time_start
;; ...
;; time_stop
;;
;; Läs tiden genom att undersöka värdet i $f1 (BSD-format)
time = $f1
.macro time_start .macro time_start
PHA PHA
LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1
;;;;Clear all time data and set time =1. ;;;;Clear all time data and set time =1.
AND #%11110000 AND #%11110000
STA $DC08 STA $DC08
INC $DC08 INC $DC08
LDA $DC08 LDA $DC08
;;Time is only at bit 0 ..3 ;;Time is only at bit 0 ..3
AND #%00001111 AND #%00001111
STA $f1 STA time
PLA PLA
.endmacro .endmacro
.macro time_stop .macro time_stop
PHA PHA
LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1
AND #%00001111 AND #%00001111
SEC SEC
SBC $f1 SBC time
STA $f1 STA time
PLA PLA
.endmacro .endmacro

View file

@ -1,14 +1,16 @@
;;Not values but register position in memory ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
X_end = $04
Y_end = $05 ;;Not values but register position in memory
X_pos = $FC X_end = $04
Y_pos = $FB Y_end = $05
dy= $0c X_pos = $FC
dx = dy Y_pos = $FB
dy_2 = $0607 dy= $0c
dx_2 = dy_2 dx = dy
V = $0809 dy_2 = $0607
D = $0a0b dx_2 = dy_2
;;These are also used in pixel_draw. Look there to find out more V = $0809
byte_to_paint = $FE ;Byte with one 1 that corasponds to a pixel. D = $0a0b
btp_mem_pos =$494A; byte to paint memory position ;Position of byte on screen ;;These are also used in pixel_draw. Look there to find out more
byte_to_paint = $FE ;Byte with one 1 that corasponds to a pixel.
btp_mem_pos =$494A; byte to paint memory position ;Position of byte on screen

View file

@ -1,44 +1,45 @@
.proc line; X_pos =< X_end skall alltid gälla ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; note that these have same adresses as stuff in line.inc
;; This should be used as a optimisation in the future
dx = $0c
dy = $06
;;dx
SEC
LDA X_end
SBC X_pos
STA dx
BCC dx_no_underflow;; X_end >= X_pos
EOR #$ff ; Fix bit underflow
dx_no_underflow:
SEC .proc line; X_pos =< X_end skall alltid gälla
LDA Y_pos ;; note that these have same adresses as stuff in line.inc
SBC Y_end ;; This should be used as a optimisation in the future
STA dy dx = $0c
BCC down ;normal Y_pos < Y_end dy = $06
;;dx
SEC
LDA X_end
SBC X_pos
STA dx
BCC dx_no_underflow;; X_end >= X_pos
EOR #$ff ; Fix bit underflow
dx_no_underflow:
SEC
LDA Y_pos
SBC Y_end
STA dy
BCC down ;normal Y_pos < Y_end
up:; Y_pos > Y_end up:; Y_pos > Y_end
STA dy STA dy
CMP dx CMP dx
BCC shallow; dy < dx BCC shallow; dy < dx
steep: steep:
jsr line_up_inv jsr line_up_inv
RTS RTS
shallow: ;dy =< dx shallow: ;dy =< dx
lda dx lda dx
jsr line_up jsr line_up
RTS RTS
down: down:
EOR #$ff ; Fix bit underflow EOR #$ff ; Fix bit underflow
STA dy STA dy
CMP dx CMP dx
BCC shallow_; dy < dx BCC shallow_; dy < dx
steep_: steep_:
jsr line_down_inv jsr line_down_inv
RTS RTS
shallow_: ;dy < dx shallow_: ;dy < dx
jsr line_down jsr line_down
RTS RTS
.endproc .endproc
.include "line_down.s" .include "line_down.s"
.include "line_down_inv.s" .include "line_down_inv.s"

View file

@ -1,98 +1,103 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;drawing line from 2 cordinates ;;drawing line from 2 cordinates
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg!
.proc line_down .proc line_down
;;# (X_pos, Y_pos) # .include "line.inc"; Defines memory positions, ex X_pos
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg!
.include "line.inc"; Defines memory positions, ex X_pos
;;We need to clear this memory ;;We need to clear this memory
LDA #$00 LDA #$00
STA <V STA <V
STA <dy_2 STA <dy_2
STA $FD ; for pixel_draw STA $FD ; for pixel_draw
;; V = 2*(dx -dy) ;; V = 2*(dx -dy)
;; where: dy = Y_end - Y_start, dx = OO - X_start ;; where: dy = Y_end - Y_start, dx = OO - X_start
LDA Y_end LDA Y_end
SEC SEC
SBC Y_pos SBC Y_pos
STA >V STA >V
STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V) STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA X_end LDA X_end
SEC SEC
SBC X_pos SBC X_pos
STA dx STA dx
SEC SEC
SBC >V SBC >V
STA >V; <V = dx - dy STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy) mult_16 >V, <V; V = 2*(dx -dy)
;dy_2 = dy*2 ;dy_2 = dy*2
mult_16 >dy_2, <dy_2, ! mult_16 >dy_2, <dy_2, !
;; D = 2*dy - dx ;; D = 2*dy - dx
;; In loop we have that D = D -V ;; In loop we have that D = D -V
;; So D needs to be at least >=V. ;; So D needs to be at least >=V.
;; V_max = 00000001 11111111 ;; V_max = 00000001 11111111
;; For us to work with unsigned numbers we add 00000001 11111111 ;; For us to work with unsigned numbers we add 00000001 11111111
;; to V and the branch logic to V! ;; to V and the branch logic to V!
;;D = 2*dy - dx + 2*255 ;;D = 2*dy - dx + 2*255
;;Our D is bigger then wikipedia because D is unsigned. ;;Our D is bigger then wikipedia because D is unsigned.
LDA >dy_2 LDA >dy_2
STA >D STA >D
LDA <dy_2 LDA <dy_2
STA <D STA <D
Add_16 >D, <D, #$ff, #$01, ! Add_16 >D, <D, #$ff, #$01, !
Sub_16 >D, <D, dx, #$00 Sub_16 >D, <D, dx, #$00
LDY #$00 LDY #$00
jsr pixel_draw ;;only used first pixel. after this relative position is abused jsr pixel_draw ;;only used first pixel. after this relative position is abused
;;From line_test_time this is at program_start + list_file_offset = $080D + $0116 = $0923
for_x: for_x:
;; Lets increment btp_mem_pos with +8 ;; Lets increment btp_mem_pos with +8
;; Read more in pixel_draw to understand this! ;; Read more in pixel_draw to understand this!
LDX #$00 LDX #$00
LDA byte_to_paint LDA byte_to_paint
ORA (>btp_mem_pos, X) ORA (>btp_mem_pos, X)
STA (>btp_mem_pos, X) STA (>btp_mem_pos, X)
increment_pixel_x: increment_pixel_x:
CLC CLC
ROR byte_to_paint ROR byte_to_paint
BCS move_8px_left BCS move_8px_left
JMP increment_pixel_x_end JMP increment_pixel_x_end
move_8px_left: move_8px_left:
;; add +8 to btp_mem_pos. Find more of why in pixel_draw ;; add +8 to btp_mem_pos. Find more of why in pixel_draw
Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00 Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00
;; reset byte_to_paint ;; reset byte_to_paint
LDA #%10000000 LDA #%10000000
STA byte_to_paint STA byte_to_paint
increment_pixel_x_end: increment_pixel_x_end:
INC X_pos;; legacy INC X_pos;; legacy
LDX X_pos LDX X_pos
CPX X_end CPX X_end
BEQ end BEQ end
;;If D < %00000010 00000000: case_2 ;;If D < %00000010 00000000: case_2
;;else case 1. ;;else case 1.
Lag_16 >D, <D, #$00, #$02, case_2 Lag_16 >D, <D, #$00, #$02, case_2
case_1:; C =1 so we can use ! case_1:; C =1 so we can use !
Sub_16 >D, <D, >V, <V, ! ; D = D - V Sub_16 >D, <D, >V, <V, ! ; D = D - V
increment_y_pos: increment_y_pos:
Add_16 >btp_mem_pos, <btp_mem_pos, #$01, #$00 Add_16 >btp_mem_pos, <btp_mem_pos, #$01, #$00
INY INY
CPY #$08 ; CPY #$08 ;
BEQ move_8px_down BEQ move_8px_down
jmp for_x jmp for_x
move_8px_down: ; Z=1 --> C=1 move_8px_down: ; Z=1 --> C=1
;; +320-8 bytes ;; +320-8 bytes
LDY #$00 LDY #$00
Add_16 >btp_mem_pos, <btp_mem_pos,#$38 , #$01 Add_16 >btp_mem_pos, <btp_mem_pos,#$38 , #$01
jmp for_x jmp for_x
increment_y_pos_end: increment_y_pos_end:
case_2: ;; C =0 because LAG_16 so we can use ! case_2: ;; C =0 because LAG_16 so we can use !
Add_16 >D, <D, >dy_2, <dy_2, ! ;D = D + 2*dy Add_16 >D, <D, >dy_2, <dy_2, ! ;D = D + 2*dy
JMP for_x JMP for_x
end: end:
RTS RTS
.endproc .endproc

View file

@ -1,92 +1,93 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;drawing line from 2 cordinates ;;drawing line from 2 cordinates
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg!
.proc line_down_inv .proc line_down_inv
;;# (X_pos, Y_pos) # .include "line.inc"; Defines memory positions, ex X_pos
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg!
.include "line.inc"; Defines memory positions, ex X_pos
;;We need to clear this memory ;;We need to clear this memory
LDA #$00 LDA #$00
STA <V STA <V
STA <dx_2 STA <dx_2
STA $FD ; for pixel_draw STA $FD ; for pixel_draw
;; V = 2*(dy -dx) ;; V = 2*(dy -dx)
;; where: dy = Y_end - Y_start, dx = X_end - X_start ;; where: dy = Y_end - Y_start, dx = X_end - X_start
LDA X_end LDA X_end
SEC SEC
SBC X_pos SBC X_pos
STA >V STA >V
STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V) STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V)
LDA Y_end LDA Y_end
SEC SEC
SBC Y_pos SBC Y_pos
STA dy STA dy
SEC SEC
SBC >V SBC >V
STA >V; <V = dy - dx STA >V; <V = dy - dx
mult_16 >V, <V; V = 2*(dy -dx) mult_16 >V, <V; V = 2*(dy -dx)
;dx_2 = dx*2 ;dx_2 = dx*2
mult_16 >dx_2, <dx_2 mult_16 >dx_2, <dx_2
;;D = 2*dy - dx + 2*255 ;;D = 2*dy - dx + 2*255
;;Our D is bigger then wikipedia because D is unsigned. ;;Our D is bigger then wikipedia because D is unsigned.
LDA >dx_2 LDA >dx_2
STA >D STA >D
LDA <dx_2 LDA <dx_2
STA <D STA <D
Add_16 >D, <D, #$ff, #$01 Add_16 >D, <D, #$ff, #$01
Sub_16 >D, <D, dy, #$00 Sub_16 >D, <D, dy, #$00
LDY #$00 LDY #$00
jsr pixel_draw ;;only used first pixel. after this relative position is abused jsr pixel_draw ;;only used first pixel. after this relative position is abused
CLC ; this makes it that C =0 always on for_x CLC ; this makes it that C =0 always on for_x
for_y: for_y:
LDX #$00 LDX #$00
LDA byte_to_paint LDA byte_to_paint
ORA (>btp_mem_pos, X) ORA (>btp_mem_pos, X)
STA (>btp_mem_pos, X) STA (>btp_mem_pos, X)
increment_y_pos: increment_y_pos:
Add_16 >btp_mem_pos, <btp_mem_pos, #$01, #$00, ! ; I know that C ==0 on for_y Add_16 >btp_mem_pos, <btp_mem_pos, #$01, #$00, ! ; I know that C ==0 on for_y
INY INY
CPY #$08 ; CPY #$08 ;
BEQ move_8px_down BEQ move_8px_down
jmp increment_y_pos_end jmp increment_y_pos_end
move_8px_down: move_8px_down:
;; +320-8 bytes ;; +320-8 bytes
LDY #$00 LDY #$00
Add_16 >btp_mem_pos, <btp_mem_pos,#$38 , #$01 Add_16 >btp_mem_pos, <btp_mem_pos,#$38 , #$01
increment_y_pos_end: increment_y_pos_end:
INC Y_pos;; legacy INC Y_pos;; legacy
LDX Y_pos LDX Y_pos
CPX Y_end CPX Y_end
BEQ end BEQ end
;;If D < %00000010 00000000: case_2
;;If D < %00000010 00000000: case_2 ;;else case 1.
;;else case 1. Lag_16 >D, <D, #$00, #$02, case_2
Lag_16 >D, <D, #$00, #$02, case_2
case_1: case_1:
Sub_16 >D, <D, >V, <V; D = D - V Sub_16 >D, <D, >V, <V; D = D - V
increment_pixel_x: increment_pixel_x:
CLC CLC
LDA byte_to_paint LDA byte_to_paint
ROR byte_to_paint ROR byte_to_paint
BCS move_8px_left BCS move_8px_left
JMP for_y JMP for_y
move_8px_left: move_8px_left:
;; add +8 to btp_mem_pos. Find more of why in pixel_draw ;; add +8 to btp_mem_pos. Find more of why in pixel_draw
Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00 Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00
;; reset byte_to_paint ;; reset byte_to_paint
LDA #%10000000 LDA #%10000000
STA byte_to_paint STA byte_to_paint
JMP for_y JMP for_y
case_2: ;; C =0 because LAG_16 so we can use ! case_2: ;; C =0 because LAG_16 so we can use !
Add_16 >D, <D, >dx_2, <dx_2, ! ;D = D + 2*dx Add_16 >D, <D, >dx_2, <dx_2, ! ;D = D + 2*dx
JMP for_y JMP for_y
end: end:
RTS RTS
.endproc .endproc

View file

@ -1,90 +1,84 @@
X_end = $04 ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
Y_end = $05
X_pos = $FC .include "line.inc"
Y_pos = $FB ;;for testing stuff
;;for testing stuff Y_pos_ = $0D
Y_pos_ = $0D X_pos_ = $0E
X_pos_ = $0E Y_end_ = $10
Y_end_ = $10 X_end_ = $11
X_end_ = $11 LDA #$d0
LDA #$d0 STA X_pos_
STA X_pos_ LDA #$60
LDA #$60 STA Y_pos_
STA Y_pos_ LDA #$ff
LDA #$ff STA X_end
STA X_end LDA #$0
LDA #$0 STA Y_end
STA Y_end
;; Short test for timing ;; Short test for timing
@loop: @loop:
LDA Y_pos_ LDA Y_pos_
STA Y_pos STA Y_pos
LDA X_pos_ LDA X_pos_
STA X_pos STA X_pos
jsr line jsr line
INC Y_end INC Y_end
LDA Y_end LDA Y_end
CMP #$bb CMP #$bb
BEQ end__ BEQ end__
jmp @loop jmp @loop
end__: end__:
;; Full anfle test ;; Full anfle test
@loop: @loop:
LDA Y_pos_ LDA Y_pos_
STA Y_pos STA Y_pos
LDA X_pos_ LDA X_pos_
STA X_pos STA X_pos
jsr line jsr line
INC Y_end INC Y_end
LDA Y_end LDA Y_end
CMP #$bb CMP #$bb
BEQ end BEQ end
jmp @loop jmp @loop
end: end:
;;Long lines ;;Long lines
;;Lets cleer bitmap
LDA #>VIC_bank
STA $FC
LDA #<VIC_bank
STA $FB
;;Lets cleer bitmap LDA #>$5f3f
LDA #>VIC_bank STA $FE
STA $FC LDA #<$5f3f
LDA #<VIC_bank STA $FD
STA $FB
LDA #>$5f3f LDA #$0
STA $FE jsr memory_rec
LDA #<$5f3f
STA $FD
LDA #$0 LDA #$00
jsr memory_rec STA X_pos_
LDA #$60
LDA #$00 STA Y_pos_
STA X_pos_ LDA #$ff
LDA #$60 STA X_end
STA Y_pos_ LDA #$0
LDA #$ff STA Y_end
STA X_end
LDA #$0
STA Y_end
@loop: @loop:
LDA Y_pos_ LDA Y_pos_
STA Y_pos STA Y_pos
LDA X_pos_ LDA X_pos_
STA X_pos STA X_pos
jsr line
jsr line INC Y_end
INC Y_end LDA Y_end
LDA Y_end CMP #$bb
CMP #$bb BEQ end_
BEQ end_ jmp @loop
jmp @loop
end_: end_:
jmp exit jmp exit
.include "line.s" .include "line.s"
.include "macros/" .include "macros/"

View file

@ -1,38 +1,36 @@
X_end = $04 ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
Y_end = $05
X_pos = $FC
Y_pos = $FB
;;for testing stuff
Y_pos_ = $0D
X_pos_ = $0E
Y_end_ = $10
X_end_ = $11
LDA #$00
STA X_pos_
LDA #$30
STA Y_pos_
LDA #$ff
STA X_end
LDA #$30
STA Y_end
;; Short test for timing .include "line.inc"
time_start ;;for testing stuff
Y_pos_ = $0D
X_pos_ = $0E
Y_end_ = $10
X_end_ = $11
LDA #$00
STA X_pos_
LDA #$30
STA Y_pos_
LDA #$ff
STA X_end
LDA #$30
STA Y_end
;; Short test for timing
time_start
@loop:;; mem f1 @loop:;; mem f1
LDA Y_pos_ LDA Y_pos_
STA Y_pos STA Y_pos
LDA X_pos_ LDA X_pos_
STA X_pos STA X_pos
jsr line jsr line_down
INC Y_end INC Y_end
LDA Y_end LDA Y_end
CMP #$50 CMP #$50
BEQ end__ BEQ end__
jmp @loop jmp @loop
end__: end__:
time_stop time_stop
jmp exit jmp exit
.include "line.s" .include "line_down.s"

View file

@ -1,77 +1,70 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;drawing line from 2 cordinates ;;drawing line from 2 cordinates
;;# * (X_end, Y_end) #
;;# #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
.proc line_up .proc line_up
;;# * (X_end, Y_end) # .include "line.inc"; Defines memory positions, ex X_pos
;;# #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
.include "line.inc"; Defines memory positions, ex X_pos
;;example values ~~~~~ SHOULD BE PRECOMPILED ;;We need to clear this memory
;LDA #$90 LDA #$00
;STA X_pos STA <V
;STA Y_pos STA <dy_2
;LDA #$aa STA $FD ; for pixel_draw
;STA X_end
;LDA #$80
;STA Y_end
;;~~~~~~~~~~
;;We need to clear this memory ;; V = 2*(dx -dy)
LDA #$00 ;; where: dy = Y_pos - Y_end, dx = X_end - X_start
STA <V ;; This logic is comented out because line.s does it woithout any
STA <dy_2 ;;extra cost. May be needed in the future so it will stay as coments!
STA $FD ; for pixel_draw LDA Y_pos
SEC
SBC Y_end
STA >V
STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA X_end
SEC
SBC X_pos
STA dx
SEC
SBC >dy_2
STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy)
;; V = 2*(dx -dy) ;dy_2 = dy*2
;; where: dy = Y_pos - Y_end, dx = X_end - X_start mult_16 >dy_2, <dy_2
;; This logic is comented out because line.s does it woithout any
;;extra cost. May be needed in the future so it will stay as coments!
LDA Y_pos
SEC
SBC Y_end
STA >V
STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA X_end
SEC
SBC X_pos
STA dx
SEC
SBC >dy_2
STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy)
;dy_2 = dy*2 ;;D = 2*dy - dx + 2*255
mult_16 >dy_2, <dy_2 ;;Our D is bigger then wikipedia because D is unsigned.
LDA >dy_2
;;D = 2*dy - dx + 2*255 STA >D
;;Our D is bigger then wikipedia because D is unsigned. LDA <dy_2
LDA >dy_2 STA <D
STA >D Add_16 >D, <D, #$ff, #$01
LDA <dy_2 Sub_16 >D, <D, dx, #$00
STA <D
Add_16 >D, <D, #$ff, #$01
Sub_16 >D, <D, dx, #$00
for_x: for_x:
jsr pixel_draw jsr pixel_draw
;;Increment X until X_pos = X_end and Y_pos = Y_end ;;Increment X until X_pos = X_end and Y_pos = Y_end
INC X_pos INC X_pos
LDX X_pos LDX X_pos
CPX X_end CPX X_end
BEQ end BEQ end
;;If D < %00000010 00000000: case_2 ;;If D < %00000010 00000000: case_2
;;else case 1. ;;else case 1.
Lag_16 >D, <D, #$00, #$02, case_2 Lag_16 >D, <D, #$00, #$02, case_2
case_1: case_1:
DEC Y_pos DEC Y_pos
Sub_16 >D, <D, >V, <V; D = D - V Sub_16 >D, <D, >V, <V; D = D - V
JMP for_x JMP for_x
case_2: case_2:
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
JMP for_x JMP for_x
end: end:
RTS RTS
.endproc .endproc

View file

@ -1,64 +1,67 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;drawing line from 2 cordinates ;drawing line from 2 cordinates
;;# (X_end, Y_end) #
;;# * #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;NOTE THAT Y_pos >) Y_end, X_pos <= X_end. Min 45deg!
.proc line_up_inv .proc line_up_inv
;;# (X_end, Y_end) # include "line.inc"
;;# * #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;NOTE THAT Y_pos >) Y_end, X_pos <= X_end. Min 45deg!
.include "line.inc"
;;We need to clear this memory ;We need to clear this memory
LDA #$00 LDA #$00
STA <V STA <V
STA <dx_2 STA <dx_2
STA $FD ; for pixel_draw STA $FD ; for pixel_draw
;; V = 2*(dy -dx) ;; V = 2*(dy -dx)
;; where: dy = Y_pos - Y_end, dx = X_end - X_start ;; where: dy = Y_pos - Y_end, dx = X_end - X_start
LDA X_end LDA X_end
SEC SEC
SBC X_pos SBC X_pos
STA >V STA >V
STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V) STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA Y_pos LDA Y_pos
SEC SEC
SBC Y_end SBC Y_end
STA dy STA dy
SEC SEC
SBC >V SBC >V
STA >V; <V = dx - dy STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy) mult_16 >V, <V; V = 2*(dx -dy)
;dy_2 = dy*2 ;dy_2 = dy*2
mult_16 >dx_2, <dx_2 mult_16 >dx_2, <dx_2
;;D = 2*dx - dy + 2*255 ;;D = 2*dx - dy + 2*255
;;Our D is bigger then wikipedia because D is unsigned. ;;Our D is bigger then wikipedia because D is unsigned.
LDA >dx_2 LDA >dx_2
STA >D STA >D
LDA <dx_2 LDA <dx_2
STA <D STA <D
Add_16 >D, <D, #$ff, #$01 Add_16 >D, <D, #$ff, #$01
Sub_16 >D, <D, dy, #$00 Sub_16 >D, <D, dy, #$00
for_y: for_y:
jsr pixel_draw jsr pixel_draw
;;Increment Y until Y_pos = Y_end and X_pos = X_end ;;Increment Y until Y_pos = Y_end and X_pos = X_end
DEC Y_pos DEC Y_pos
LDY Y_pos LDY Y_pos
CPY Y_end CPY Y_end
BEQ end BEQ end
;;If D < %00000010 00000000: case_2 ;;If D < %00000010 00000000: case_2
;;else case 1. ;;else case 1.
Lag_16 >D, <D, #$00, #$02, case_2 Lag_16 >D, <D, #$00, #$02, case_2
case_1: case_1:
INC X_pos INC X_pos
Sub_16 >D, <D, >V, <V; D = D - V Sub_16 >D, <D, >V, <V; D = D - V
JMP for_y JMP for_y
case_2: case_2:
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy
JMP for_y JMP for_y
end: end:
RTS RTS
.endproc .endproc

View file

@ -1,3 +1,4 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;##### HANDLES BIG MEMORY MANAGMENTS ############ ;;##### HANDLES BIG MEMORY MANAGMENTS ############
;;recursive write to memory. ;;recursive write to memory.

View file

@ -1,3 +1,5 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;Screen print. Draws a pixel at a specified position. ;;Screen print. Draws a pixel at a specified position.
;; Destroys A X Y ;; Destroys A X Y
.proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200 .proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200

View file

@ -1,7 +1,10 @@
# !/bin/bash # !/bin/bash
killall x64sc killall x64sc
#Note that program start at $080D
cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg -l file.list source.s \ cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg -l file.list source.s \
&& nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 file.prg </dev/null &>/dev/null & && nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 file.prg </dev/null &>/dev/null &
sleep 2 sleep 2
rm source.o rm source.o
rm file.prg