Jump to content
IGNORED

Division not working in the standard kernel


freshbrood

Recommended Posts

Am I doing something wrong? I understand that I need to insert "include div_mul.asm" at the start but it still doesn't seem to work with anything that doesn't divide evenly. n = 105 / 7 crashes.

n = (105 / 7) crashes. I don't need any floating number, I only want the int.

 

 

Also, unrelated, why are there only 6 banks listed in the dpc+ template instead of 8?
 

Link to comment
Share on other sites

17 minutes ago, freshbrood said:

Am I doing something wrong? I understand that I need to insert "include div_mul.asm" at the start but it still doesn't seem to work with anything that doesn't divide evenly. n = 105 / 7 crashes.

n = (105 / 7) crashes. I don't need any floating number, I only want the int.

 

 

Also, unrelated, why are there only 6 banks listed in the dpc+ template instead of 8?
 

 

Not a solution to your problem, but just a bit of advice: avoid division like the plague.

It is slow, and there are nearly always better ways to organise things into shifts and/or adds/subtracts/increments/decrements

For example, if you could somehow change the need for a 7 into an 8, then you could just shift right 3 times. 8 cycles.

The general purpose division routine is going to be lots more than that - say... 50... 100? More?

 

 

  • Like 2
Link to comment
Share on other sites

This probably should be posted in the BBasic sub-forum.

 

But I can give an answer for the last question:

You only have 6 code banks available in DPC+ (24k).  The other 8k is used as follows:   4k  is used for the Display Data RAM.  3k is used by the DPC bankswitching driver.  1k is used for music frequencies/only accessible via ARM code.

  • Like 1
Link to comment
Share on other sites

As @Andrew Davie mentions division by powers of 2 can be done fast, others not so much. That said, @Omegamatrix has a blog entry with a number of optimized division routines, such as this for divide by 7. Note that the code in the blog entry is messed up due to the last forum upgrade, so download the file DivisionRoutines(rev2).asm

;Divide by 7 (From December '84 Apple Assembly Line)
;15 bytes, 27 cycles
  sta  temp
  lsr
  lsr
  lsr
  adc  temp
  ror
  lsr
  lsr
  adc  temp
  ror
  lsr
  lsr

 

This is the DPC+ cartridge layout, can read more about it here - DPC+ARM - Part 6, DPC+ Cartridge Layout1372137226_ScreenShot2021-01-06at11_43_28AM.thumb.png.059ac66694f408bc500b5b937d7293b6.png 

 

  • Like 1
Link to comment
Share on other sites

Not sure if this addresses your 2nd question directly:

The template was made by me a long time ago, I don't know if it was updated after iesposta noticed an error in it.

Batari Basic indexes the banks starting at 1 through 6, the template said that bank 6 was reserved for the graphics bank because I had indexed the banks starting from 0 back then. Bank 6 is in fact usable as it translates to bank 5 as SpiceWare posted above.

 

So if your coding in ASM then DPC+ uses banks 0-5 for user code, bank 6 is reserved for the graphic data copies and fast fetcher access.

In bB you have banks 1-6 for use, and bank 7 is the graphics bank.

Edited by ScumSoft
  • Like 1
Link to comment
Share on other sites

Thanks for all your clear replies, I appreciate it! You save me a lot of headache and make writing games fun. I'm just getting into dpc now and even peeked at Karl G's asm for beginners tutorials, excellent. It's less daunting with you guys to help and your awesome input.
 

 

Btw I thought I was already posting in the batari forum??
 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...