It turns out he'd already turned off everything he could and the discussion moved on to other optimisations he could use. I'd like to know what can be 'turned off' and how to do it and what complications can arise from this. I'm happy to be pointed at some books but I'll most likely return with more questions after my reading.SteveO wrote:I seem to remember you can wring slightly more speed out of the Beeb for games by turning off some routine tasks undertaken by the OS. For example keyboard scanning. Now I think I'm already doing this with the code RTW gave me for vertical scrolling. But are there any other areas that can be turned of to improve speed a little ? And if so how ?
Since I'm currently interested in writing games stopping the OS from butting in seems to be a good idea but I know Tricky has mentioned turning off the OS a few times and how sound in particular can be a problem.
One of the pieces of example code over as RS is 'Reading the keyboard by direct hardware access' by RTW and at the end of the text he writes:
I've written a small piece of code using this technique which checks for the standard beeb game keys of zx:/ and space then prints them to the screen . I'm curious if (1) I've done it correctly and (2) if turning off the OS would satisfy the interrupts disabled part of the above meaning I could remove the sei/cli instructions from my code.RTW wrote:All of this has to be done either with interrupts disabled, or a custom IRQ handler in place which doesn't let the OS in, otherwise all of the setup will be undone by OS code (because these values are changed to play sounds, for example).
Code: Select all
\\ 'Dirty' keyboard input oswrch = $ffee ORG &1900 .start \\ MODE 1 lda #$16 jsr oswrch lda #1 jsr oswrch .loop jsr movement jmp loop rts \\ readkeys taken from retrosoftware.co.uk example code here \\ - http://www.retrosoftware.co.uk/wiki/index.php?title=Reading_the_keyboard_by_direct_hardware_access - \\ written by rtw .readkeys \\ initialisation lda #0 \\set all keys to 0 sta left sta right sta up sta down sta fire sei; turn interrupts off LDA #&7F:STA &FE43; set DDRA to 01111111 LDA #&0F:STA &FE42; allow write to addressable latch LDA #&03:STA &FE40; set bit 3 to 0 \\ keys checked here \\ z - left - code 97 LDA #97:STA &FE4F:LDA &FE4F \ N flag = whether 'Z' pressed bpl not_z lda #1 sta left .not_z \\ x - right - code 66 LDA #66:STA &FE4F:LDA &FE4F \ N flag = whether 'X' pressed bpl not_x lda #1 sta right .not_x \\ colon - up - code 72 LDA #72:STA &FE4F:LDA &FE4F \ N flag = whether ':' pressed bpl not_colon lda #1 sta up .not_colon \\ slash - down - code 104 LDA #104:STA &FE4F:LDA &FE4F \ N flag = whether '/' pressed bpl not_slash lda #1 sta down .not_slash \\ space - fire - code 98 LDA #98:STA &FE4F:LDA &FE4F \ N flag = whether ' ' pressed bpl not_space lda #1 sta fire .not_space cli; turn interrupts back on rts .movement jsr readkeys lda left beq no_left lda #90 jsr oswrch .no_left lda right beq no_right lda #88 jsr oswrch .no_right lda up beq no_up lda #58 jsr oswrch .no_up lda down beq no_down lda #47 jsr oswrch .no_down lda fire beq key_end lda #32 jsr oswrch .key_end rts \\store inputs .left equb 0 .right equb 0 .up equb 0 .down equb 0 .fire equb 0 .end SAVE "KEYS",start,end