How do you clear the screen in machine language?

Basic and Machine Language

Moderator: Moderators

Post Reply
JRBasic
Vic 20 Newbie
Posts: 17
Joined: Thu Dec 20, 2018 10:31 am
Occupation: Programmer

How do you clear the screen in machine language?

Post 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.
20questions
Vic 20 Hobbyist
Posts: 114
Joined: Sun Mar 10, 2019 7:39 pm
Location: lodi california
Occupation: student

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

Post by 20questions »

Bedroom coder=rock star
modern coder= pop star
i'd rather be a rock star than a pop start 8)
JRBasic
Vic 20 Newbie
Posts: 17
Joined: Thu Dec 20, 2018 10:31 am
Occupation: Programmer

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

Post by JRBasic »

Thanks, cleared the screen as you said.
User avatar
OmegaMax
Vic 20 Newbie
Posts: 12
Joined: Fri Mar 08, 2019 9:59 pm
Location: Canada

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

Post 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?
User avatar
OmegaMax
Vic 20 Newbie
Posts: 12
Joined: Fri Mar 08, 2019 9:59 pm
Location: Canada

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

Post 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


Forbidden64
Vic 20 Hobbyist
Posts: 146
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

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

Post 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.
User avatar
OmegaMax
Vic 20 Newbie
Posts: 12
Joined: Fri Mar 08, 2019 9:59 pm
Location: Canada

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

Post by OmegaMax »

I write all my own code,but use whatever suits you best.
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

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

Post 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.
Post Reply