Page 1 of 1

How do you clear the screen in machine language?

Posted: Thu Mar 28, 2019 6:56 pm
by JRBasic
How do you clear the screen in machine language? I'm trying to make my first VIC-20 demo in CBM prg Studio.

Re: How do you clear the screen in machine language?

Posted: Thu Mar 28, 2019 7:34 pm
by 20questions

Re: How do you clear the screen in machine language?

Posted: Thu Mar 28, 2019 7:50 pm
by JRBasic
Thanks, cleared the screen as you said.

Re: How do you clear the screen in machine language?

Posted: Thu Mar 28, 2019 8:06 pm
by OmegaMax
Might be a good idea to clear the screen memory with your own code instead of using the kernal,if your going to program the VIC in assembly,starting with small routines/code is a good idea.

Code: Select all

Do_ClearScreenRam
  ldy #0
  lda #$20
ClearScreenRamLoop
  sta $1e00,y
  sta $1f00,y
  iny
  bne ClearScreenRamLoop
  rts
What type of demo are you doing?

Re: How do you clear the screen in machine language?

Posted: Thu Mar 28, 2019 8:31 pm
by OmegaMax
Since your description says "Occupation: Programmer" then you understand pointers,so here's a small program that uses pointers.It clears the screen ram and then draws @ using a pointer.Copy code into CBM prg studio,feel free to play around with the code so you can understanding how it works.

Code: Select all

*=$1001                         
 byte $0B,$10,$DC,$07
 byte $9E,$34,$31,$30,$39
 byte $00,$00,$00

 jmp Main
;-----------------------------------
; VIC 20 Color Defines
;-----------------------------------
Black = 0
White = 1
Red = 2
Cyan = 3
Purple = 4 
Green = 5
Blue = 6
Yellow = 7
Orange = 8
LightOrange = 9 
Pink = 10
LightCyan = 11 
LightPurple = 12
LightGreen = 13
LightBlue = 14
LightYellow = 15
;-----------------------------------
; Defines
;-----------------------------------
ScreenRam = $1e00
GridCharacter = $00
BlankCharacter = $20
;-----------------------------------
; Variables
;-----------------------------------
Pointer = $00

Main
  jsr Do_ClearScreenRam
  jsr Do_DrawGridToScreenRam
LoopForever
  jmp LoopForever

;-----------------------------------
;
;-----------------------------------
Do_ClearScreenRam
  ldy #0
  lda #BlankCharacter
ClearScreenRamLoop
  sta ScreenRam+0,y
  sta ScreenRam+256,y
  iny
  bne ClearScreenRamLoop
  rts
;-----------------------------------
; Draw And Color Grid
;-----------------------------------
Do_DrawGridToScreenRam
  lda #>ScreenRam
  sta Pointer+1
  lda #<ScreenRam+44
  sta Pointer+0
  ldx #18                 ;ScreenRows
DrawNextRowLoop
  ldy #20                 ;ScreenColumns
DrawNextColumnLoop        
  lda #GridCharacter
  sta (Pointer),y
  lda Pointer+1
  pha
  clc
  adc #$78
  sta Pointer+1
ColorNextColumn
  lda #Red                
  sta (Pointer),y
  pla
  sta Pointer+1
  dey                      
  bne DrawNextColumnLoop   
  lda Pointer+0            
  clc
  adc #22                  
  sta Pointer+0            
  lda Pointer+1           
  adc #0
  sta Pointer+1            
  dex                        
  bne DrawNextRowLoop      
  rts



Re: How do you clear the screen in machine language?

Posted: Sat Mar 30, 2019 6:48 pm
by Forbidden64
OmegaMax wrote:Might be a good idea to clear the screen memory with your own code instead of using the kernal,if your going to program the VIC in assembly,starting with small routines/code is a good idea.
Even some of the most picky assembly folks on denial use the kernal routines as a convenient library of commands. It is good to know what the routine does, however. That said, once you do there is no reason not to use kernal routines unless you have/need a much faster/custom routine. I've heard even expert demo scene guys like Michael Steil say they use the floating point stuff built in because its fast and already there.

Re: How do you clear the screen in machine language?

Posted: Sat Mar 30, 2019 11:00 pm
by OmegaMax
I write all my own code,but use whatever suits you best.

Re: How do you clear the screen in machine language?

Posted: Sun Mar 31, 2019 1:25 am
by srowe
Forbidden64 wrote:Even some of the most picky assembly folks on denial use the kernal routines as a convenient library of commands. It is good to know what the routine does, however. That said, once you do there is no reason not to use kernal routines unless you have/need a much faster/custom routine. I've heard even expert demo scene guys like Michael Steil say they use the floating point stuff built in because its fast and already there.
The KERNAL routines are often useful, unfortunately the screen code has 22x23 hardcoded so if you are using a different size you have to end up writing your own.