Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Show Koala Pic
2014-11-09 19:57
Ejner

Registered: Oct 2012
Posts: 43
Show Koala Pic

I'm sure noone here has any problems with showing a simple Koala picture, but I came across this piece of code on codebase64.org and wondered why this had to be done so complicated...?

http://codebase64.org/doku.php?id=base:calculate_vic_settings_f..

In TurboAssembler it's pretty simple to calculate the VIC settings, see my example below. Isn't something similar possible with KickAssembler? Just wondering...

Example in TurboAssembler:

;---------------------------------------
;        Show Koala
;---------------------------------------
koala    = $6000
screen   = $5c00
;---------------------------------------
bank     = koala/$4000

         *= $1000

         lda #$3b
         sta $d011
         lda #koala-($4000*bank)/1024
         ora #(screen-($4000*bank))/64
         sta $d018
         lda #$d8
         sta $d016
         lda $dd02
         ora #%00000011
         sta $dd02
         lda $dd00
         and #%11111100
         ora #3-bank
         sta $dd00

         ldx #0
copy     lda koala+$1f40,x
         sta screen,x
         lda koala+$2040,x
         sta screen+$0100,x
         lda koala+$2140,x
         sta screen+$0200,x
         lda koala+$2228,x
         sta screen+$02e8,x
         lda koala+$2328,x
         sta $d800,x
         lda koala+$2428,x
         sta $d900,x
         lda koala+$2528,x
         sta $da00,x
         lda koala+$2610,x
         sta $dae8,x
         inx
         bne copy
         lda koala+$2710
         sta $d021
         lsr a
         lsr a
         lsr a
         lsr a
         sta $d020

         lda #0
         cmp $0277     ;wait for key
         bne *-3

         lda $dd02
         ora #%00000011
         sta $dd02
         lda $dd00
         and #%11111100
         ora #%00000011
         sta $dd00
         lda #$1b
         sta $d011
         lda #$15
         sta $d018
         lda #$c8
         sta $d016

         jmp $9000
;---------------------------------------

Note: The result of "bank = koala/$4000" is an integer.
2014-11-09 20:07
Mace

Registered: May 2002
Posts: 1799
This shows how it's done in detail.
Of course for your own program, you can change it, but for educational purposes, it's sometimes easier to follow when everything is written in all detail.
2014-11-09 20:09
Burglar

Registered: Dec 2004
Posts: 1101
.macro set_bank(screenram,bitmap) {
    .var cur_dd00   = [ >screenram >> 6 ] ^ %00000011
    .eval screenram = screenram & $3fff
    .eval bitmap    = bitmap & $3fff
    .var cur_d018   = [ [ >screenram << 2 ] + [ >bitmap >> 2 ] ]

    lda $dd00
    and #%1111100
    ora #cur_dd00
    sta $dd00
    lda #cur_d018
    sta $d018
}
and then you can :set_bank($0400,$2000)
2014-11-09 21:00
Ejner

Registered: Oct 2012
Posts: 43
Thanks Burglar, thats a neat little snippet of code there :-)
2014-12-16 17:15
Burglar

Registered: Dec 2004
Posts: 1101
annoying bug in the macro I posted. finally found out that *that* was causing random weirdness in 1 out of 20 runs or so.
lda $dd00
and #%11111100 <-- one more bit added
ora #cur_dd00
sta $dd00

subtle type, I was anding with #$7c instead of #$fc. it will bug your loader possibly. also might add that even this fixed one isnt 100% stable if you use it while loading
2014-12-16 22:58
Slammer

Registered: Feb 2004
Posts: 416
Burglars way of doing it is pretty handy.. Especially when setting dd00. An alternative way of doing these things are defining functions like:

.function screenToD018(addr) {
	.return [[addr&$3fff]/$400]<<4
}
.function charsetToD018(addr) {
	.return [[addr&$3fff]/$800]<<1
}
.function toD018(screen, charset) {
	.return screenToD018(screen) | charsetToD018(charset)
}

.function toSpritePtr(addr) {
	.return [addr&$3fff]/$40
}
etc.

With functions like these you can do:
lda #toD018(logoScreen, logoCharset)
sta $d018
but also make tables if thats what you need:
.byte toD018(screen1,charset), toD018(screen2,charset)


So here you gain a little flexibility but have to type some more
2014-12-19 05:13
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
as the book says:

selectchar

lda $d018
and #240
ora #0 ;0-2-4-6-8-10-12-14 : 0000-07ff, 0800-0fff, 1000-17ff, 1800-1fff
; 2000-27ff, 2800-2fff, 3000-37ff, 3800-3fff
sta $d018
2014-12-21 17:36
Ejner

Registered: Oct 2012
Posts: 43
Hey, I see this thread is still cooking :-)

Thanks for all the examples, they are really helpful and give inspiration for digging a little deeper into all the smooth possibilities with f.i. KickAssembler, it seems like a really handy tool with lots of flexibility once you get the hang of it :-)

I think this thread now provides some nice examples that are all much smoother ways of calculating the VIC settings than the codebase example (no offence)...

Trying to learn a little from the examples above, does this compute in KickAssembler terminology?

koala    = $6000
screen   = $5c00

         *= $1000

         lda #[koala & $3fff]/1024
         ora #[screen & $3fff]/64
         sta $d018
         lda $dd00
         and #%11111100
         ora #3-[>koala >> 6]
         sta $dd00
2014-12-21 22:37
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
this is unreadable code:
lda #[koala & $3fff]/1024
ora #[screen & $3fff]/64
sta $d018
lda $dd00
and #%11111100
ora #3-[>koala >> 6]
sta $dd00

lda d018
ora xxx
sta d018

can be read!

lda dd00
and xxx
ora 0-1-2-3
sta dd00

can be read


i tried kickasm.. its russian gibberish to me :)
2015-02-22 19:20
Ejner

Registered: Oct 2012
Posts: 43
koala =  $6000
screen = $5c00

         *= $1000

         lda #[>koala & $3f]/4
         ora #[screen & $3fff]/64
         sta $d018
         lda $dd00
         and #%11111100
         ora #3-[>koala >> 6]
         sta $dd00

Breaking it down...
         lda #[koala & $3fff]/1024
...will take the address of the koala, then AND it with $3fff to skip the first two bits which define the VIC bank, and then divide this with 1024, which is actually LSR'ing 10 times to get the remaining bits in the right location for $d018. Treatet as a word, but the result is a byte.

         ora #[screen & $3fff]/64
...same, but will LSR only 6 times.

         ora #3-[>koala >> 6]
...">koala" will take only the highbyte of the koala address. Then it is LSR'ed 6 times, leaving only the two bits that define the VIC bank. "3-" will invert those two bits.


Hope this helps for better understanding...
2015-02-22 19:33
chatGPZ

Registered: Dec 2001
Posts: 11386
hooray for using proper constants (and dont listen to rambones, hardcoding values is never better)

just one thing - why doing LDA# followed by ORA#? you can just write it like
Quote:

lda #[[>koala & $3f]/4]|[[screen & $3fff]/64]

also, use bitshifts instead of divides, it makes it easier to see what happens (IMHO)
 
... 32 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 | 4 | 5 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Jazzcat/Onslaught
csabanw
Metal Maniac/Dual Crew
Operator Teleksu
algorithm
El Jefe/Slackers^sidD
Dan
MWR/Visdom
McGurk/Coma
Xiny6581/Dees Produc..
Morpheus/IPC+C64.COM
E$G/HF ⭐ 7
Guests online: 108
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.047 sec.