Use non-compressed DSK images with http links. Valid also with ROMs

This commit is contained in:
Ivan Izaguirre 2019-07-07 17:40:29 +02:00
parent f53b849a52
commit 67a92895b3
2 changed files with 19 additions and 2 deletions

View File

@ -39,9 +39,9 @@ casa@servidor:~$ ./apple2sdl
![DOS 3.3 started](doc/dos33.png)
### Play games
Download an DSK file ([Asimov](https://mirrors.apple2.org.za/ftp.apple.asimov.net/images/) is an excellent source) and use the `-disk` parameter.
Download an DSK file locally or use the a link ([Asimov](https://www.apple.asimov.net/images/) is an excellent source) with the `-disk` parameter:
```
casa@servidor:~$ ./apple2sdl -disk ~/Downloads/karateka.dsk
casa@servidor:~$ ./apple2sdl -disk "https://www.apple.asimov.net/images/games/action/karateka/karateka (includes intro).dsk"
```
![Karateka](doc/karateka.png)

View File

@ -3,6 +3,7 @@ package apple2
import (
"io"
"io/ioutil"
"net/http"
"os"
"strings"
@ -11,12 +12,19 @@ import (
const (
internalPrefix = "<internal>/"
httpPrefix = "http://"
httpsPrefix = "https://"
)
func isInternalResource(filename string) bool {
return strings.HasPrefix(filename, internalPrefix)
}
func isHTTPResource(filename string) bool {
return strings.HasPrefix(filename, httpPrefix) ||
strings.HasPrefix(filename, httpsPrefix)
}
func loadResource(filename string) []uint8 {
var file io.Reader
if isInternalResource(filename) {
@ -28,6 +36,15 @@ func loadResource(filename string) []uint8 {
}
defer resourceFile.Close()
file = resourceFile
} else if isHTTPResource(filename) {
response, err := http.Get(filename)
if err != nil {
panic(err)
}
defer response.Body.Close()
file = response.Body
} else {
diskFile, err := os.Open(filename)
if err != nil {