Add hugo code

This commit is contained in:
hugova 2025-02-27 22:04:43 +01:00
parent 7fc374246a
commit 864b0e659b
8 changed files with 433 additions and 0 deletions

50
wip-hugo/README.md Executable file
View file

@ -0,0 +1,50 @@
# comodore64
# JUST F*** RUN ¯\\\_(ツ)_/¯
in terminal run
```
\. run.sh
```
## Debug
Vice --> Activate Monitor
## Chitty endian
2 bits 00 88 --> real world 8800
# Resourses
## Compiler
[cc65](https://cc65.github.io/doc/ca65.html#ss4.1)
## Comodore 64 Wiki
[wiki](https://www.c64-wiki.com/wiki/Memory_Map)
## ASEMBLY 6502 instruction set
[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)
[sprite multiplex ](https://www.c64-wiki.com/wiki/Raster_interruptg)
[sprite multiplex x2](http://selmiak.bplaced.net/games/c64/index.php?lang=eng&game=Tutorials&page=Sprite-Multiplexing)
## Documentation of the vic chip
[text](https://www.zimmers.net/cbmpics/cbm/c64/vic-ii.txt)
[vic](https://csdb.dk/release/?id=154952)
### 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/)

99
wip-hugo/STARTUP.s Executable file
View file

@ -0,0 +1,99 @@
;Settings positions
CR1 = $d011; ;Grafic settings
VIC_bank_settings = $DD00 ; Vic position
Screen_RAM_settings =$D018 ;Screan ram position relative to vic
;########## VIC_BANK ################
;# BITMAP | $4000 -$5F3F
;# Unused? | $5F3F - $6000
;# SCREAN RAM (color) | $6000 -$63E7
;# Unused? | $63E8 - $7FFF
;#
;####################################
;Memory positions
VIC_bank = $4000
VIC_bank_end = VIC_bank + $3FFF
Bitmap = VIC_bank
Bitmap_end = $5F3F
Screen_RAM = $2000 + VIC_bank
Screen_RAM_end = Screen_RAM + $03E7
;Free upp memory
;https://www.c64-wiki.com/wiki/Bank_Switching
;
;
;Sets grafic mode [Standard bitmap mode]
;https://www.c64-wiki.com/wiki/Standard_Bitmap_Mode
LDA #%10111111 ; ECM = False
AND CR1
STA CR1
LDA #%00100000; BMM = True
ORA CR1
STA CR1
; Set VIC bank to bank 1
;https://www.c64-wiki.com/wiki/VIC_bank
LDA #%11111110 ;bit_0 = False
AND VIC_bank_settings
STA VIC_bank_settings
LDA #%00000010; bit_1 = True
ORA VIC_bank_settings
STA VIC_bank_settings
;Set Scren-RAM to offset 8 ;https://www.c64-wiki.com/wiki/53272 (offset is 8k byte = 1024*8-ich)
LDA #%10001111 ; bit_6 =bit_5=bit_4 = Falsw
AND Screen_RAM_settings
STA Screen_RAM_settings
LDA #%10000000; bit_1 = True
ORA Screen_RAM_settings
STA Screen_RAM_settings
;Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM
LDA #>VIC_bank
STA $FC
LDA #<VIC_bank
STA $FB
LDA #>$5f3f
STA $FE
LDA #<$5f3f
STA $FD
LDA #$0
jsr memory_rec
;Sets the screen color to black and white
LDA #>Screen_RAM
STA $FC
LDA #<Screen_RAM
STA $FB
LDA #>Screen_RAM_end
STA $FE
LDA #<Screen_RAM_end
STA $FD
LDA #%11110000
jsr memory_rec
;Converting basic ROM to RAM mohahah
LDA #$36 ; 00110110
STA $0001
CLI ;Disable interups (not all)

48
wip-hugo/macros/16aritmatic.s Executable file
View file

@ -0,0 +1,48 @@
.macro Add_16 a_low, a_hi, b_low, b_hi ; a = a + b
CLC
LDA b_low
ADC a_low
STA a_low
LDA b_hi
ADC a_hi
STA a_hi
.endmacro
.macro mult_16 low_, hi_ ; [low, hi] = [low, hi]*2
CLC
ROL low_
ROL hi_
.endmacro
;
;.proc Sub_abs_8 ;return, primary, secondary
; LDA primary
; SEC
; SBC secondary
; BPL end_;we got z positive result
; LDA secondary
; SEC
; SBC primary
; end_:
; STA return
;.endproc
;
;.proc poer ;low, hi, in ; [low, hi] = [in]^2
; LDY in
; STY low
; LDA #$00
; STA hi
; ;pow:
; DEY ; count = count -1
; BEQ y_pow_end;
; CLC
; LDA in
; ADC low
; STA low
; LDA #$00
; ADC hi
; STA hi
; ;jmp pow
; y_pow_end:
;.endproc

View file

@ -0,0 +1,81 @@
;drawing line from 2 cordinates
.proc line
testing:
;# (X_pos, Y_pos) #
;# * #
;# * #
;# * #
;# (X_end, Y_end) #
;
; NOTE THAT X_pos <= X_end and line is going downwords max 45deg!
;Not values but register position in memory
X_end = $04
Y_end = $05
X_pos = $FC
Y_pos = $FB
dy = $06
dx = $07
D = $08
;Set values
LDA #$00
STA $FD ; for pixel_draw
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$00
STA X_pos
STA Y_pos
LDA #$50
STA X_end
STA dx
LDA #$40
STA Y_end
STA dy
LDA #($40 + $40 - $50 )
STA D ; = 2*dy - dx
; ~~~~~~~
for_x:
jsr pixel_draw
LDY D ; FOR DEBUG
; If D <= 0 then: skipp
LDX D;
DEX
BMI case_2
case_1:
INC Y_pos
;D = D_before -2*dx
LDA dx
ROL A
TAX
LDA D
STX D ; D = -2*dx, A = D_before
SEC
SBC D ; A = D_before -2*dx
STA D;
jmp last
case_2:
;D = D + 2*dx
LDA dx
ROL
CLC
ADC D
STA D
last:
CMP #$00
; increment x untill x == large
INC X_pos
LDA X_pos
CMP #199
BEQ end
JMP for_x
end:
jmp testing
.endproc

View file

@ -0,0 +1,48 @@
;##### HANDLES BIG MEMORY MANAGMENTS ############
;recursive write to memory.
.proc memory_rec
;Writes data in A
;Adress start: $FC, $FB
;Adress end: $FE, $FD
; Example [ $FC =$44, $FB =$00, $FE =$45, $FD =$01, A =0]
; writes zeros in memory from $4400 to $4501.
;put what to recursive write in Y.
LDX #$0
TAY
loop:
;write to byte
TYA
STA ($FB ,X)
TAY
Add_16 $FB, $FC, #$01, #$00
LDA $FB
CMP $FD
BEQ test_1
jmp loop
test_1:
LDA $FC
CMP $FE
BEQ test_2
jmp loop
test_2:
;Dont forget to rewrite last byte
TYA
STA ($FB, X)
RTS
.endproc

View file

@ -0,0 +1,90 @@
; Screen print. Draws a pixel at a specified position.
.proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200
;write_byte = 00010000,
LDA $FC ; X (mod 8)
AND #%00000111
;Store pixel in byte
TAX
LDA #%10000000
INX
tt:
DEX
BEQ end__;Y=0 end this
CLC
ROR A
jmp tt
end__:
STA $FE
;FIND THE POSITION IN MEMORY TO WRITE PIXEL
; + + + + + > X
; +
; +
;\/
; Y
;
; Let be this position in memory be stored in [$49, $4A] temporaraly
; pos = x_offset
LDA #%11111000
AND $FC
STA $49
LDA $FD
STA $4A
; y_offset because chuncks aka y_offset_bc
LDA #%00000111 ; A = y (mod 8)
AND $FB
; pos += y_offset_bc
CLC
ADC $49
STA $49
LDA #$00
ADC $4A
STA $4A
LDY $FB
LDA #$00
STA $4B
; y =8 translates to 320 bytes.
LDA #%11111000 ; A = y - [y (mod 8)]
AND $FB
STA $FB
;We need to A = A*40 =A * 2^3 * 5
; A = A*2^3
mult_16 $FB, $4B
mult_16 $FB, $4B
mult_16 $FB, $4B
; *5
Add_16 $49, $4A, $FB, $4B
Add_16 $49, $4A, $FB, $4B
Add_16 $49, $4A, $FB, $4B
Add_16 $49, $4A, $FB, $4B
Add_16 $49, $4A, $FB, $4B
STY $FB
;; add offset for where bitmap is
Add_16 $49, $4A, #<Bitmap, #>Bitmap
;;Let draw some stuff
LDX #$00
LDA $FE
ORA ($49, X)
STA ($49, X)
RTS
.endproc

4
wip-hugo/run.sh Executable file
View file

@ -0,0 +1,4 @@
# !/bin/bash
pkill -f pulseaudio
killall x64sc ; cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg source.s && nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 file.prg </dev/null &>/dev/null &
#https://vice-emu.sourceforge.io/vice_7.html

13
wip-hugo/source.s Executable file
View file

@ -0,0 +1,13 @@
.include "STARTUP.s"
.include "macros/16aritmatic.s"
.include "routines/memory/line_up.s"
loop_:
jmp loop_
.include "routines/memory/memory_rec.s"
.include "routines/memory/pixel_draw.s"
;.include "routines/memory/memory.s"