Thanks NYYRIKKI, that makes sense. I am still thinking in basic where you didn't have control over this, let alone do a screensplit in basic I sort of knew what it was but it seems to be much more detailed than I thought it was.
Huey: I am just beginning with this and until now interrupts have not been important for me. Maybe when I'll start programming 100% in Assembly.
Hmm, doing a simple sum, like a=1; b=5; a=a+b; store_it_in_ram, is much much easier than Hello World in asm.
Yes, at the time you start as assembly programmer: from scratch. But over time, you'll develop your own library of subroutines to make common tasks easier. Either as ready-to-cut-and-paste code snippets, or as some kind of 'fixed' BIOS that you load together with each of your programs. With that in place, assembly programming isn't much harder than writing in other languages. For example, when I need to put some text on the screen, I just use:
call print db "Hello World!",0
Which requires subroutine "print" - written once, used many times.
More difficult is project management: keeping track of all the parts, changes in each part, building end result from many small pieces etc. For small projects, this is a non-issue. For big projects, this makes difference between succeed / fail.
Thanks NYYRIKKI, that makes sense. I am still thinking in basic where you didn't have control over this, let alone do a screensplit in basic I sort of knew what it was but it seems to be much more detailed than I thought it was.
Huey: I am just beginning with this and until now interrupts have not been important for me. Maybe when I'll start programming 100% in Assembly.
Ok, ok. I just thought you were much more familiar with the MSX in and outs. Anyway. Don't give up on the assembly.
Thanks NYYRIKKI, that makes sense. I am still thinking in basic where you didn't have control over this, let alone do a screensplit in basic
Sure you have control in BASIC as well! TIME variable is driven by interrupts and there is even ON INTERVAL GOSUB command.
... and here is example of screensplit in BASIC:
http://www.msx.org/forumtopic9185.html
Ok, ok. I just thought you were much more familiar with the MSX in and outs. Anyway. Don't give up on the assembly.
you would think so after all the stuff I made for openMSX
... and here is example of screensplit in BASIC:
http://www.msx.org/forumtopic9185.html
Turbo Basic, pretty impressive though. Never thought about doing that.
you would think so after all the stuff I made for openMSX
Seriously, if you can make a Snake-It variant in BASIC within 20 hours, I'm sure you'll master this.
ASM to me seems dizzying.
O.k., who screwed up the layout first?
it's pretty cool
It seems [ quote ] directly after a url includes HTML closing tags in the url
or maybe not :P
Turbo Basic, pretty impressive though. Never thought about doing that.
Well, BASIC anyway
I'm pretty sure that I'm only one who has done this, so I can't blame you.
This is actually very good example of the problem Huey was having, so let's open up the inner working of this listing a bit:
10 ' This example program shows how to use line interrupts 20 ' Made By : NYYRIKKI 2008 30 ' 40 DEFINT A-Z 50 ' This program requires X-BASIC 60 _TURBO ON 70 GOTO 90 ' Little jump to avoid RENUM problem 80 GOTO 410 ' This line will be copied to interrupt hook 90 VDP(9)=10 ' In this example we don't need sprites, so we disable them. 100 ' Let's draw something to screen to see the line interrupt effect 110 SCREEN 8:FORY=0TO255:FORX=0TO255:VPOKEX+Y*256,XXORY:NEXTX,Y 120 ' 130 ' Let's disable interrups until we are ready (DI) 140 '#I 243 150 ' We will use general interrupt hook in address &hFD9A (-614) 160 ' This address is called every time when interrupt occurs. 170 ' To use it, we have to copy line 80 to the hook. 180 ' First we need to know in what memory address line 80 is: 190 ' AD = LINE 80 (NOTE: RENUM does not work in this case!!!) 200 '#I 33,@80,34,AD 210 ' ... and then just copy... 220 FOR I=0 TO 4:POKE -614+I,PEEK(AD+I):NEXT I 230 ' We want to have line interrupts, so let's enable them. 240 VDP(0)=VDP(0) OR 16 250 ' Let's set the interrupt to happen on line 100 260 VDP(20)=100 270 ' Now we are ready and we can enable interrupts (EI) 280 '#I 251 290 ' Do what ever you want to do here in main program 300 ' In this example we make some noise... 310 SOUND 8,15 320 SOUND 1,RND(1)*8:SOUND 0,RND(1)*255 330 IF INKEY$="" THEN 320 340 ' Before we can exit the program we have to disable line interrupts 350 VDP(0)=VDP(0) AND 239 360 ' ... and release the interrupt hook (put RETurn to it) 370 POKE -614,201 380 ' Now it is safe to exit 390 BEEP:END 400 ' 410 ' This is interrupt routine 420 ' Here we make sure, that the example interrupt handler does not end up 430 ' to infinite loop in case of nested interrupts 440 IF IN=0 THEN IN=1:GOSUB 470:IN=0:T=0 ELSE T=T+1:IF T=100 THEN T=0:IN=0 450 RETURN 460 ' 470 ' Example interrupt handler: 480 IF (VDP(-1)AND1)=1 THEN 530 ' Is this line interrupt? 490 ' This was not line interrupt, so it's propably VBLANK 500 ' VBLANK happens when screen has been drawn. 510 VDP(24)=0 ' Upper part of screen shows still picture 520 RETURN 530 ' Here we handle line interrupt 540 ' Lower part of screen jumps 550 VDP(24)=P:P=ABS(SIN(R/20)*100):R=R+1 560 RETURN
In line 440 I check that interrupt is not nested. In assembler this is not needed in any normal situation. How ever this is needed in this BASIC-program... Why?
In line 480 we check that interrupt is not caused by line interrupt... After the code is compiled the routine looks something like this:
di ld a,1 out (#99),a ld a,#8F out (#99),a in a,(#99) ld b,a xor a out (#99),a ld a,#8f out (#99),a ei ld a,b and 1 cp 1 jp z,@530
... this is just fine as long as the interrupt was actually line interrupt. BUT if it was "normal" VDP VBLANK interrupt we end up to this situation where BIOS has not reseted the VDP interrupt line (read status register 0), but we have still enabled the interrupts...
This causes the routine jump immediately back to line 440 instead of executing line 480 to the end. When we return in 450 the interrupts are disabled again and the program can execute the end of line 480.
This actually happens with every VDP-command, so the lines 440 & 450 are executed way more many times that you propably imagined.
After last return from 450 the BIOS detects that this interrupt is VBLANK and handles it correctly.
Nice NYYRIKKI!