A89: Stron89, again!!! The REAL letter!


[Prev][Next][Index][Thread]

A89: Stron89, again!!! The REAL letter!





I explained this before, and I do it again, I see you have some new questions,
so
lets get going :)

S43R80@aol.com wrote:
> 
> Phew...FINALS ARE OVER!!!...That means I have a whole month off from school to
> finally do some more assembly...So I am going to refer back to some of my old
> questions that I didn't quite understand the first time around...However, I do
> have less questions than last time :)
> ---------------------------Program begins here-----------------------------
> 
>  kbd_arrows     EQU             %111111110
>  kbd_column5    EQU             %111111101
>  kbd_column4    EQU             %111111011
>  kbd_column3    EQU             %111110111
>  kbd_column2    EQU             %111101111
>  kbd_column1    EQU             %111011111
>  kbd_exitkey    EQU             %110111111
> 
>  dir_left       EQU             0
>  dir_up         EQU             1
>  dir_right      EQU             2
>  dir_down       EQU             3
> 
>  _main:
>         bsr             WaitKBD
> 
> So basically what equ does it let a variable equal something?
>    like storing something in a mem. position?

No. What equ does is an alias for a number. the line "kbd_exitkey   
EQU             %110111111" is telling the assemblator, that every time it finds
the text "kbd_exitkey" it should replace it with "%110111111" when it
assembles.. %110111111 isn't very easy to remember and isn't very easy to
remember what it does..
 
>  ReadKBD:
>         move.w  d1,-(a7)
>         move.w  d0,d1
>         move.w  #$700,d0                    ; Disable interrupts, saving old in mask
>  in d0
>      trap    #1
> 
<...>
> Someone gave me a small explanation of the trap command before but It didn't
> quite help me :(
> regarding trap:
> 1.  Why is $700 put in d0?
> 2.  What does moving $700 in d0 have to do with trap:Is there documentation on
> all trap uses?
> 3.  It says "Disable interrupts, saving old in mask".  What interrupts are
> being disabled?
> 4.  What is the "old in mask"

Traps are "software interrupts" and they are (like interrupts) run in supervisor
mode. the supervisor mode is a mode of the 68k processor where you have access
to some system registers in the 68k. one of these are the SR which, among other
things, control the interrupt level.
The interrupt level is stored in the 3 first bits of the high byte of SR 
(%00000xxx 00000000)
Trap #1 is designed to change this interrupt level and wants a mask for which
bits to set in d0
so $700 in d0 will set all three bits, ($700 = %00000111 00000000) and put the
processor in interrupt level 7, thus preventing any interrupt with a level lower
than 7 to be executed. practically turning off all interrupts. (or int. 1-6 i
don't remember)
the old mask is a mask telling which bits where set in SR before Trap #1 was
called. making it easy to switch back to the previous interrupt level.
 
> So 0 is put into ($600018) because thats the address of the keyboard?  so your
> basically resetting it to later check what new value is stored there?
> 
> nop gives it time to detect a key press?
> 
> now a new value (if a key was pressed) is put into ,($60001b).
> 
> again with the trap 1 thing...but why is there not a value put in d0 again
> like $700...like last time???

0 into ($600018) is putting a row mask of 0 to the keyboard (as explained in the
last post)
a row mask of 0 is enabling all rows for reading, thus checking for a press on
any key (it's impossible to tell which  of 8 keys in the same column, that was
pressed)

nop's is giving the hardware time to apply the mask

if you press any key, the value of ($60001b) will change to something that isn't
$FF (all 1's)

The reason why there is no value stored in d0 at this second call, is that you
havn't changed d0 since the last call of Trap #1, therefore d0 is still holding
the old interrupt level mask, so this second call to trap #1 is resetting the
interrupt level (probably turning all ints on again)

 
> now rtsing back to waitkbd...
> 
>  WaitKBD:
>         move.w  #$00,d0                                 ; set keymask to read all keys
>         bsr             ReadKBD
>         cmp.b   #$ff,d0                                 ; check to see if any key is pressed
>         bne             WaitKBD                                 ; if so, start over
>         rts
> 
> if 0 was put in (600018) before then how will it contain $ff if nothing was
> pressed?
> did the author actually mean" if not, start over" instead of if so, start
> over?

check above.. a bit of 1 means key not pressed, a bit of 0 means key pressed.
 
 
> wow...asm is really hard...I hope there is hope for even the very
> inexperienced...well i'll know at the end of the month...
> 
> -THANKS-
>      -Steve-

I hope this letter clear some minds :)
and don't expect to know "everything" in a month, especially if you have no asm
experience from any other processor..

there is documentation of traps and stuff in the FargoII docs, and i think about
the same info is in the DoorsOS docs.. check there..  It can be a little hard to
understand if you have no "low-level" experience, but I think you can get it..

//Olle