From a617d911831a2715d04862f7571390205f172d79 Mon Sep 17 00:00:00 2001 From: hugova Date: Sun, 9 Mar 2025 23:43:59 +0100 Subject: [PATCH] Change 4 spaces indenting to 8 and add string for emacs to understand indenting rules --- wip-hugo/README.md | 8 +- wip-hugo/macros/16aritmatic.s | 71 +++++----- wip-hugo/macros/timer.s | 50 ++++--- wip-hugo/routines/line/line.inc | 30 +++-- wip-hugo/routines/line/line.s | 69 +++++----- wip-hugo/routines/line/line_down.s | 165 ++++++++++++------------ wip-hugo/routines/line/line_down_inv.s | 151 +++++++++++----------- wip-hugo/routines/line/line_test.s | 140 ++++++++++---------- wip-hugo/routines/line/line_test_time.s | 62 +++++---- wip-hugo/routines/line/line_up.s | 123 +++++++++--------- wip-hugo/routines/line/line_up_inv.s | 107 +++++++-------- wip-hugo/routines/memory/memory_rec.s | 1 + wip-hugo/routines/memory/pixel_draw.s | 2 + wip-hugo/run.sh | 3 + 14 files changed, 501 insertions(+), 481 deletions(-) diff --git a/wip-hugo/README.md b/wip-hugo/README.md index c8d26a4..1dd38d8 100755 --- a/wip-hugo/README.md +++ b/wip-hugo/README.md @@ -7,6 +7,7 @@ in terminal run ``` ## Debug Vice --> Activate Monitor +program currently start att $080D ## Chitty endian 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) [wikipedia (minimalistic)](https://en.wikibooks.org/wiki/6502_Assembly) - - ### sprites [sprite](https://www.c64-wiki.com/wiki/Sprite#Sprite_priority) @@ -38,13 +37,10 @@ Vice --> Activate Monitor ### Holding hand instructions :) [codeburst hard asembly code](https://codeburst.io/lets-write-some-harder-assembly-language-code-c7860dcceba) - [flag intro](http://www.6502.org/tutorials/vflag.html) - - ## Basic [peek and poke](https://en.wikipedia.org/wiki/PEEK_and_POKE) # Cool unexplored tools -[text](https://style64.org/cbmdisk/documentation/) \ No newline at end of file +[text](https://style64.org/cbmdisk/documentation/) diff --git a/wip-hugo/macros/16aritmatic.s b/wip-hugo/macros/16aritmatic.s index ed2cba5..8079493 100755 --- a/wip-hugo/macros/16aritmatic.s +++ b/wip-hugo/macros/16aritmatic.s @@ -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! -;; And X or Y is b_hi -;; 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 +;;Se below for some fast 16bit logic +;;http://6502.org/tutorials/compare_beyond.html + +;; 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 .ifblank fast_unsafe CLC @@ -16,8 +22,10 @@ STA a_hi .endmacro -; Untested! -.macro Add_16_AX low, hi, fast_unsafe; , A, X +;; Untested! +;; 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 .ifblank fast_unsafe CLC @@ -29,20 +37,25 @@ STA hi .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 - SEC + SEC .endif - LDA a_low - SBC b_low - STA a_low - LDA a_hi - SBC b_hi - STA a_hi + LDA a_low + SBC b_low + STA a_low + LDA a_hi + SBC b_hi + STA a_hi .endmacro -;;Untested -.macro Sub_16_AX low, hi, fast_unsafe; , A, X +;; Untested +;; 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 .ifblank fast_unsafe SEC @@ -54,7 +67,9 @@ STA hi .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 .ifblank fast_unsafe CLC @@ -62,18 +77,16 @@ ROL low_ ROL hi_ .endmacro -;;Se below for some fast 16bit logic -;;http://6502.org/tutorials/compare_beyond.html -;; exampel 4.1.1 -;;Larger then operation. IF a < b then jump to label +;;Larger then operation, uses the A register +;;IF a < b then: jump to label .macro Lag_16 a_low, a_hi, b_low, b_hi, label ; [low, hi] = [low, hi]*2 - LDA a_hi ; compare high bytes - CMP b_hi - BCC label ; if NUM1H < NUM2H then NUM1 < NUM2 - BNE LABEL ; if NUM1H <> NUM2H then NUM1 > NUM2 (so NUM1 >= NUM2) - LDA a_low ; compare low bytes - CMP b_low - BCC label ; if NUM1L < NUM2L then NUM1 < NUM2 - LABEL: + LDA a_hi + CMP b_hi + BCC label + BNE LABEL + LDA a_low + CMP b_low + BCC label + LABEL: .endmacro diff --git a/wip-hugo/macros/timer.s b/wip-hugo/macros/timer.s index 5db6b14..92c7059 100644 --- a/wip-hugo/macros/timer.s +++ b/wip-hugo/macros/timer.s @@ -1,26 +1,34 @@ -;; Max 1.5s eller 0.9s vet ej villken -;; skriv time_start .. kod .. time_stop -;; och läs värdet i f1 +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;; 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 - PHA - LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 - ;;;;Clear all time data and set time =1. - AND #%11110000 - STA $DC08 - INC $DC08 - LDA $DC08 - ;;Time is only at bit 0 ..3 - AND #%00001111 - STA $f1 - PLA + PHA + LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 + ;;;;Clear all time data and set time =1. + AND #%11110000 + STA $DC08 + INC $DC08 + LDA $DC08 + ;;Time is only at bit 0 ..3 + AND #%00001111 + STA time + PLA .endmacro .macro time_stop - PHA - LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 - AND #%00001111 - SEC - SBC $f1 - STA $f1 - PLA + PHA + LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 + AND #%00001111 + SEC + SBC time + STA time + PLA .endmacro diff --git a/wip-hugo/routines/line/line.inc b/wip-hugo/routines/line/line.inc index b7d9fcd..f1ef87d 100644 --- a/wip-hugo/routines/line/line.inc +++ b/wip-hugo/routines/line/line.inc @@ -1,14 +1,16 @@ - ;;Not values but register position in memory - X_end = $04 - Y_end = $05 - X_pos = $FC - Y_pos = $FB - dy= $0c - dx = dy - dy_2 = $0607 - dx_2 = dy_2 - V = $0809 - D = $0a0b - ;;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 +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;;Not values but register position in memory + X_end = $04 + Y_end = $05 + X_pos = $FC + Y_pos = $FB + dy= $0c + dx = dy + dy_2 = $0607 + dx_2 = dy_2 + V = $0809 + D = $0a0b + ;;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 diff --git a/wip-hugo/routines/line/line.s b/wip-hugo/routines/line/line.s index 3e7a289..8a89541 100644 --- a/wip-hugo/routines/line/line.s +++ b/wip-hugo/routines/line/line.s @@ -1,44 +1,45 @@ -.proc line; X_pos =< X_end skall alltid gälla - ;; 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: +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- - SEC - LDA Y_pos - SBC Y_end - STA dy - BCC down ;normal Y_pos < Y_end +.proc line; X_pos =< X_end skall alltid gälla + ;; 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 + LDA Y_pos + SBC Y_end + STA dy + BCC down ;normal Y_pos < Y_end up:; Y_pos > Y_end - STA dy - CMP dx - BCC shallow; dy < dx + STA dy + CMP dx + BCC shallow; dy < dx steep: - jsr line_up_inv - RTS + jsr line_up_inv + RTS shallow: ;dy =< dx - lda dx - jsr line_up - RTS + lda dx + jsr line_up + RTS down: - EOR #$ff ; Fix bit underflow - STA dy - CMP dx - BCC shallow_; dy < dx + EOR #$ff ; Fix bit underflow + STA dy + CMP dx + BCC shallow_; dy < dx steep_: - jsr line_down_inv - RTS + jsr line_down_inv + RTS shallow_: ;dy < dx - jsr line_down - RTS + jsr line_down + RTS .endproc .include "line_down.s" .include "line_down_inv.s" diff --git a/wip-hugo/routines/line/line_down.s b/wip-hugo/routines/line/line_down.s index 2319b3d..7082617 100644 --- a/wip-hugo/routines/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -1,98 +1,103 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + ;;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 - ;;# (X_pos, Y_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 + .include "line.inc"; Defines memory positions, ex X_pos - ;;We need to clear this memory - LDA #$00 - 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 >V - STA >V; V, 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 >V + STA >V; V, dy_2, =V. - ;; V_max = 00000001 11111111 - ;; For us to work with unsigned numbers we add 00000001 11111111 - ;; to V and the branch logic to V! + ;dy_2 = dy*2 + mult_16 >dy_2, =V. + ;; V_max = 00000001 11111111 + ;; For us to work with unsigned numbers we add 00000001 11111111 + ;; to V and the branch logic to V! - ;;D = 2*dy - dx + 2*255 - ;;Our D is bigger then wikipedia because D is unsigned. - LDA >dy_2 - STA >D - LDA D, D, dy_2 + STA >D + LDA D, D, btp_mem_pos, X) - STA (>btp_mem_pos, X) + ;; Lets increment btp_mem_pos with +8 + ;; Read more in pixel_draw to understand this! + LDX #$00 + LDA byte_to_paint + ORA (>btp_mem_pos, X) + STA (>btp_mem_pos, X) increment_pixel_x: - CLC - ROR byte_to_paint - BCS move_8px_left - JMP increment_pixel_x_end + CLC + ROR byte_to_paint + BCS move_8px_left + JMP increment_pixel_x_end move_8px_left: - ;; add +8 to btp_mem_pos. Find more of why in pixel_draw - Add_16 >btp_mem_pos, btp_mem_pos, D, D, D, V, D, V, btp_mem_pos, btp_mem_pos, C=1 - ;; +320-8 bytes - LDY #$00 - Add_16 >btp_mem_pos, btp_mem_pos, D, dy_2, D, dy_2, V - STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V) - LDA Y_end - SEC - SBC Y_pos - STA dy - SEC - SBC >V - STA >V; V, V + STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V) + LDA Y_end + SEC + SBC Y_pos + STA dy + SEC + SBC >V + STA >V; V, dx_2, dx_2, dx_2 - STA >D - LDA D, D, dx_2 + STA >D + LDA D, D, btp_mem_pos, X) -STA (>btp_mem_pos, X) + LDX #$00 + LDA byte_to_paint + ORA (>btp_mem_pos, X) + STA (>btp_mem_pos, X) increment_y_pos: - Add_16 >btp_mem_pos, btp_mem_pos, btp_mem_pos, btp_mem_pos, D, D, D, V, D, V, btp_mem_pos, btp_mem_pos, D, dx_2, D, dx_2, VIC_bank + STA $FC + LDA #VIC_bank -STA $FC -LDA #$5f3f + STA $FE + LDA #<$5f3f + STA $FD -LDA #>$5f3f -STA $FE -LDA #<$5f3f -STA $FD + LDA #$0 + jsr memory_rec -LDA #$0 -jsr memory_rec - -LDA #$00 -STA X_pos_ -LDA #$60 -STA Y_pos_ -LDA #$ff -STA X_end -LDA #$0 -STA Y_end + LDA #$00 + STA X_pos_ + LDA #$60 + STA Y_pos_ + LDA #$ff + STA X_end + LDA #$0 + STA Y_end @loop: - LDA Y_pos_ - STA Y_pos - LDA X_pos_ - STA X_pos - - jsr line - INC Y_end - LDA Y_end - CMP #$bb - BEQ end_ - jmp @loop + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + jsr line + INC Y_end + LDA Y_end + CMP #$bb + BEQ end_ + jmp @loop end_: -jmp exit - + jmp exit .include "line.s" .include "macros/" diff --git a/wip-hugo/routines/line/line_test_time.s b/wip-hugo/routines/line/line_test_time.s index 7806575..053546c 100644 --- a/wip-hugo/routines/line/line_test_time.s +++ b/wip-hugo/routines/line/line_test_time.s @@ -1,38 +1,36 @@ - X_end = $04 - 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 +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- -;; Short test for timing -time_start + .include "line.inc" + ;;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 - LDA Y_pos_ - STA Y_pos - LDA X_pos_ - STA X_pos + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos - jsr line - INC Y_end - LDA Y_end - CMP #$50 - BEQ end__ - jmp @loop + jsr line_down + INC Y_end + LDA Y_end + CMP #$50 + BEQ end__ + jmp @loop end__: -time_stop -jmp exit + time_stop + jmp exit -.include "line.s" +.include "line_down.s" diff --git a/wip-hugo/routines/line/line_up.s b/wip-hugo/routines/line/line_up.s index 3d7f2b4..73ee4bc 100644 --- a/wip-hugo/routines/line/line_up.s +++ b/wip-hugo/routines/line/line_up.s @@ -1,77 +1,70 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + ;;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 - ;;# * (X_end, Y_end) # - ;;# # - ;;# * # - ;;# * # - ;;# (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 + .include "line.inc"; Defines memory positions, ex X_pos - ;;example values ~~~~~ SHOULD BE PRECOMPILED - ;LDA #$90 - ;STA X_pos - ;STA Y_pos - ;LDA #$aa - ;STA X_end - ;LDA #$80 - ;STA Y_end - ;;~~~~~~~~~~ + ;;We need to clear this memory + LDA #$00 + 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, 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, dy_2, dy_2, dy_2 - STA >D - LDA D, D, dy_2 + STA >D + LDA D, D, D, D, D, V, D, V, D, dy_2, D, dy_2, ) Y_end, X_pos <= X_end. Min 45deg! + .proc line_up_inv - ;;# (X_end, Y_end) # - ;;# * # - ;;# * # - ;;# * # - ;;# (X_pos, Y_pos) # - ;;NOTE THAT Y_pos >) Y_end, X_pos <= X_end. Min 45deg! - .include "line.inc" + include "line.inc" - ;;We need to clear this memory - LDA #$00 - STA V - STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V) - LDA Y_pos - SEC - SBC Y_end - STA dy - SEC - SBC >V - STA >V; V, V + STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V) + LDA Y_pos + SEC + SBC Y_end + STA dy + SEC + SBC >V + STA >V; V, dx_2, dx_2, dx_2 - STA >D - LDA D, D, dx_2 + STA >D + LDA D, D, D, D, D, V, D, V, D, dx_2, D, dx_2, /dev/null & sleep 2 rm source.o +rm file.prg