Author Topic: How do you do bank switching in NASM?  (Read 7601 times)

Offline Wannabe Developer

  • Jr. Member
  • *
  • Posts: 9
How do you do bank switching in NASM?
« on: May 17, 2011, 05:53:41 PM »
The title says it all

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: How do you do bank switching in NASM?
« Reply #1 on: May 17, 2011, 07:39:34 PM »
The place you just bounced back from, OSDev.org, has a topic related to your question.

Other then that, I recommend acquiring Michael Abrash's Zen of Graphics Programming and start digging into the fundamentals of what you are trying to achieve.

Offline Wannabe Developer

  • Jr. Member
  • *
  • Posts: 9
Re: How do you do bank switching in NASM?
« Reply #2 on: May 18, 2011, 03:52:31 AM »
The place you just bounced back from, OSDev.org, has a topic related to your question.

Other then that, I recommend acquiring Michael Abrash's Zen of Graphics Programming and start digging into the fundamentals of what you are trying to achieve.

This was exactly what I was looking for! It's great to be able to post on a forum and get an actual answer without having to put up with annoyances

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How do you do bank switching in NASM?
« Reply #3 on: May 18, 2011, 09:00:37 AM »
"How do you do bank-switching?" Reluctantly! If you can get a Linear Frame Buffer (or use OS/Xwindows services to do it for you), that's probably a better bet. If you're stuck with 64k segments, you may need to do bank-switching.

For VGA modes, there'a a port...

Code: [Select]
        xor bx,bx
sbank:
;To set a 64k bank number in single paging mode use the following procedure:

;PortW[$3CE] := bank_number Shl 12 + $09;
mov dx,03CEh
mov ax,bx
shl ax,0Ch
add ax,09h
out dx,ax

For higher res modes (VESA) there's a BIOS interrupt...

Code: [Select]
; bank in dx
SwitchBank:
    push ax
    push bx
    mov ax,4f05h
    xor bx,bx
    int 10h
    pop bx
    pop ax
    ret

Since I tried to avoid bank-switching, that's about all I know about it. There's some "setup" involved before those will work, so I'll attach the files they're snipped from. I don't know where "vid94.asm" came from. I believe "hires.asm" was derived from "garfvid.asm" - something posted by a guy who went by "Garfield" (if I ever knew his right name, I've forgotten) which I attempted to "improve" for him. His original "PutPixel" ("lint" in this version) calls SwitchBank whether the bank needs to be switched or not. My "pp2" checks to see if it needs to be switched. Should be faster - I don't really recall. I don't think any of 'em do anything "interesting", but they're examples of "bank-switching in Nasm".

Best,
Frank